Skip to content

Commit

Permalink
Switch to processing Ruby front matter by default (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite authored Sep 10, 2020
1 parent e71c86d commit 4449663
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
8 changes: 2 additions & 6 deletions bridgetown-core/features/rendering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,17 @@ Feature: Rendering
And I should see "Hi there, John Doe!" in "output/index.html"
And I should not see "Build Warning:" in the build output

Scenario: Execute inline Ruby if ENV is set
Scenario: Execute inline Ruby
Given I have a _posts directory
And I have the following post:
| title | date | layout | cool | content |
| Page | 2020-01-01 | simple | !ruby/string:Rb \|\n "Very" + " Cool".upcase | Something {{ page.cool }} |
And I have a "index.html" page with layout "simple" that contains "{% for post in site.posts %}{{ post.content }}{% endfor %}"
And I have a simple layout that contains "{{ content }}"
And I have an env var BRIDGETOWN_RUBY_IN_FRONT_MATTER set to true
When I run bridgetown build
And I delete the env var BRIDGETOWN_RUBY_IN_FRONT_MATTER
Then I should see "Very COOL" in "output/index.html"

Scenario: Don't execute inline Ruby if ENV is not set
Scenario: Don't execute inline Ruby if ENV is set to false
Given I have a _posts directory
And I have the following post:
| title | date | layout | cool | content |
Expand Down Expand Up @@ -181,7 +179,5 @@ Feature: Rendering
| Page | 2020-01-01 | simple | #\n nested_cool: !ruby/string:Rb \|\n "Very Very" + " Cool".upcase | Something {{ page.cool.nested_cool }} |
And I have a "index.html" page with layout "simple" that contains "{% for post in site.posts %}{{ post.content }}{% endfor %}"
And I have a simple layout that contains "{{ content }}"
And I have an env var BRIDGETOWN_RUBY_IN_FRONT_MATTER set to true
When I run bridgetown build
And I delete the env var BRIDGETOWN_RUBY_IN_FRONT_MATTER
Then I should see "Very Very COOL" in "output/index.html"
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def render
Bridgetown::Hooks.trigger :site, :post_render, self, payload
end

# Executes inline Ruby frontmatter if
# +ENV+["BRIDGETOWN_RUBY_IN_FRONTMATTER"] equals "true"
# Executes inline Ruby frontmatter
#
# @example
# calculation: !ruby/string:Rb |
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Configuration < ActiveSupport::HashWithIndifferentAccess
"limit_posts" => 0,
"future" => false,
"unpublished" => false,
"ruby_in_front_matter" => true, # requires BRIDGETOWN_RUBY_IN_FRONT_MATTER == "true"
"ruby_in_front_matter" => true,

# Conversion
"markdown" => "kramdown",
Expand Down Expand Up @@ -276,7 +276,7 @@ def add_default_excludes
end

def should_execute_inline_ruby?
ENV["BRIDGETOWN_RUBY_IN_FRONT_MATTER"] == "true" &&
ENV["BRIDGETOWN_RUBY_IN_FRONT_MATTER"] != "false" &&
self["ruby_in_front_matter"]
end

Expand Down
9 changes: 9 additions & 0 deletions bridgetown-website/src/_docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ a staging area and copy files from there to your web server.
<p><code class="flag">--unpublished</code></p>
</td>
</tr>
<tr class="setting">
<td>
<p class="name"><strong>Ruby Front Matter</strong></p>
<p class="description">Process <a href="/docs/front-matter/#ruby-front-matter" data-no-swup="true">Ruby front matter</a> (default true)</p>
</td>
<td class="has-text-centered">
<p><code class="option">ruby_in_front_matter: BOOL</code></p>
</td>
</tr>
<tr class="setting">
<td>
<p class="name"><strong>LSI</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-website/src/_docs/front-matter.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ you may encounter build errors.
For advanced use cases where you wish to generate dynamic values for front matter variables, you can use Ruby Front Matter (new in Bridgetown v0.13). This feature is available for pages, posts, and other documents–as well as layouts for site-wide access to your Ruby return values.

{% rendercontent "docs/note" %}
This requires the environment variable `BRIDGETOWN_RUBY_IN_FRONT_MATTER` to be set to `"true"` in your development and deployment setups. Otherwise the code will not be executed and will be treated as a raw string.
Prior to v0.17, this required the environment variable `BRIDGETOWN_RUBY_IN_FRONT_MATTER` to be set to `"true"`, otherwise the code would not be executed and would be treated as a raw string.
{% endrendercontent %}

[Here's a blog post with a high-level overview](/feature/supercharge-your-bridgetown-site-with-ruby-front-matter/){:data-no-swup="true"} of what Ruby Front Matter is capable of and why you might want to use it.
Expand Down

0 comments on commit 4449663

Please sign in to comment.