-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Serbea 1.0 into Bridgetown (#440)
* Integrate Serbea 1.0 into Bridgetown * Add additional Serbea documentation * don't italicize erb/serbea syntax * serbea formatting
- Loading branch information
1 parent
f7491c8
commit 09cecb7
Showing
19 changed files
with
343 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require "serbea" | ||
require "rouge/lexers/serbea" | ||
|
||
module Bridgetown | ||
class SerbeaView < ERBView | ||
include Serbea::Helpers | ||
|
||
def partial(partial_name, options = {}, &block) | ||
options.merge!(options[:locals]) if options[:locals] | ||
options[:content] = capture(&block) if block | ||
|
||
partial_segments = partial_name.split("/") | ||
partial_segments.last.sub!(%r!^!, "_") | ||
partial_name = partial_segments.join("/") | ||
|
||
Tilt::SerbeaTemplate.new( | ||
site.in_source_dir(site.config[:partials_dir], "#{partial_name}.serb") | ||
).render(self, options) | ||
end | ||
end | ||
|
||
module Converters | ||
class SerbeaTemplates < Converter | ||
priority :highest | ||
input :serb | ||
|
||
# Logic to do the Serbea content conversion. | ||
# | ||
# @param content [String] Content of the file (without front matter). | ||
# @param convertible [ | ||
# Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout] | ||
# The instantiated object which is processing the file. | ||
# | ||
# @return [String] The converted content. | ||
def convert(content, convertible) | ||
return content if convertible.data[:template_engine].to_s != "serbea" | ||
|
||
serb_view = Bridgetown::SerbeaView.new(convertible) | ||
|
||
serb_renderer = Tilt::SerbeaTemplate.new(convertible.relative_path) { content } | ||
|
||
if convertible.is_a?(Bridgetown::Layout) | ||
serb_renderer.render(serb_view) do | ||
convertible.current_document_output | ||
end | ||
else | ||
serb_renderer.render(serb_view) | ||
end | ||
end | ||
|
||
def matches(ext, convertible) | ||
if convertible.data[:template_engine].to_s == "serbea" || | ||
(convertible.data[:template_engine].nil? && | ||
@config[:template_engine].to_s == "serbea") | ||
convertible.data[:template_engine] = "serbea" | ||
return true | ||
end | ||
|
||
super(ext).tap do |ext_matches| | ||
convertible.data[:template_engine] = "serbea" if ext_matches | ||
end | ||
end | ||
|
||
def output_ext(ext) | ||
ext == ".serb" ? ".html" : ext | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
###ruby | ||
front_matter do | ||
layout :default | ||
title "I am Ruby. Here me roar!" | ||
end | ||
### | ||
|
||
markdownify <<~MARKDOWN | ||
> Well, _this_ is quite interesting! =) | ||
MARKDOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<%= @level %>: <%= content %> | ||
<%= render (Nested.new(level: @level + 1)) do %>Level <%= @level + 1 %><% end %> | ||
<% if @level == 4 %> | ||
<%= markdownify("**#{site.config.level} 4!!**") %> | ||
<%= markdownify("**#{site.config.level} 4!!**\n") %> | ||
<% end %> |
12 changes: 12 additions & 0 deletions
12
bridgetown-core/test/source/src/_components/nested_serb.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class NestedSerb < Bridgetown::Component | ||
def initialize(level:) | ||
@level = level | ||
@site = Bridgetown::Current.site | ||
end | ||
|
||
def render? | ||
@level < 5 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ @level }}: {{ content }} | ||
{%@ Nested level: @level + 1 do %}Level {{ @level + 1 }}{% end %} | ||
{% if @level == 4 %} | ||
{{ "**#{site.config.level} 4!!**" | markdownify }} | ||
{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
layout_var: | ||
- test | ||
--- | ||
|
||
<div>Test? {%= layout[:layout_var].first %}</div> | ||
|
||
<h1>{{ page.data.title }}</h1> | ||
|
||
{%= yield %} | ||
|
||
{%= partial "testing/partials", locals: { yes: "yes." } %} | ||
{%= render "testing/partials", yes: "YES!!" %} | ||
|
||
<footer>{%= site.time %} / {%= Bridgetown::VERSION %}</footer> |
1 change: 1 addition & 0 deletions
1
bridgetown-core/test/source/src/_partials/testing/_partials.serb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A partial success? {{ yes }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
layout: serblayout | ||
title: I'm an Serbea Page | ||
page_var: 123 | ||
--- | ||
|
||
One two three: {%= page.data[:page_var] * 10 %} | ||
|
||
{%= liquid_render "test_component", param: "Liquid FTW!" %} | ||
|
||
Oats, {{ ["peas", "beans", "barley"] | array_to_sentence_string }} grow. | ||
|
||
{%= markdownify do %} | ||
## I'm a header! | ||
|
||
* Yay! | ||
{%= "* Nifty!" %} | ||
{% end %} | ||
|
||
{% test_capturing = capture do %} | ||
This is how {%= "#{"cap"}turing" %} works! | ||
{% end %} | ||
|
||
{{ test_capturing | reverse }} | ||
|
||
<p class="{%= class_map blank: !''.empty?, truthy: true, 'more-truthy' => 'yes' == 'yes', falsy: nil, 'more-falsy' => 'no' == 'yes' %}">classes!</p> | ||
|
||
{%@ RubyComponent %} | ||
|
||
{%= render(Card.new(title: "I'm a card", footer: "I'm a footer")) do |c| %} | ||
{% c.image do %} | ||
<img src="test.jpg" /> | ||
{% end %} | ||
<p>I'm the body of the {%= c.kind %}</p> | ||
{% end %} | ||
|
||
{%@ Card title: "Nope", footer: "CANCEL!" do %} | ||
Canceled! | ||
{% end %} | ||
|
||
{%= render (NestedSerb.new(level: 1)) do %}Level 1{% end %} | ||
|
||
{%= render Example::OverrideComponent.new %} | ||
|
||
=== | ||
{%= test_block_helpers do |item| %} | ||
{%= item[:value] %} | ||
{% end %} | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require "helper" | ||
|
||
class TestSerbea < BridgetownUnitTest | ||
def setup | ||
@site = fixture_site | ||
@site.process | ||
@serb_page = @site.resources.find { |p| p.data[:title] == "I'm an Serbea Page" } | ||
end | ||
|
||
context "Serbea page" do | ||
should "render page vars" do | ||
assert_includes @serb_page.output, "One two three: 1230" | ||
end | ||
|
||
should "render Liquid components" do | ||
assert_includes @serb_page.output, "<span id='include-param'>Liquid FTW!</span>" | ||
end | ||
|
||
should "render Ruby/Serbea components" do | ||
assert_includes @serb_page.output, "1: Level 1" | ||
assert_includes @serb_page.output, "<p>** 4!!**</p>" | ||
end | ||
|
||
should "provide full suite of Liquid filters" do | ||
assert_includes @serb_page.output, "Oats, peas, beans, and barley grow." | ||
end | ||
|
||
should "allow Markdown content via a helper" do | ||
assert_includes @serb_page.output, "<h2 id=\"im-a-header\">I’m a header!</h2>" | ||
assert_includes @serb_page.output, "<li>Yay!</li>" | ||
assert_includes @serb_page.output, "<li>Nifty!</li>" | ||
end | ||
|
||
should "allow capturing into a variable" do | ||
assert_includes @serb_page.output, "This is how capturing works!".reverse | ||
end | ||
|
||
should "properly handle block expressions" do | ||
assert_includes @serb_page.output, "\n===\n+Value: value+\n---\n" | ||
end | ||
end | ||
|
||
context "Serbea layout" do | ||
should "render layout vars" do | ||
assert_includes @serb_page.output, "Test? test" | ||
assert_includes @serb_page.output, "<h1>I'm an Serbea Page</h1>" | ||
|
||
assert_includes @serb_page.output, "<footer>#{@site.time} / #{Bridgetown::VERSION}</footer>" | ||
end | ||
|
||
should "render partials" do | ||
assert_includes @serb_page.output, "A partial success? yes." | ||
assert_includes @serb_page.output, "A partial success? YES!!" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.