Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example use of {{ . }} #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/2/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,18 @@ Above, we've set special attributes `icon` and `days` which are now availble:
</tbody>
</table>

Now we can access these attributes with the following Mustache tags:

{{#raw_code}}
<h1>{{ page.title }}</h1>
<img title="{{ page.icon }}" src="{{ media.url }}/{{ page.icon }}.png"</img>
<p>It will be sunny on the following days:</p>
<ul>
{{# page.days }}
<li>{{ . }}</li> <!-- the '.' accesses the current element/item of the 'page.days' array/list -->
{{/page.days}}
</ul>
{{/raw_code}}

## page.content

Expand Down
13 changes: 10 additions & 3 deletions docs/2/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,20 @@ A mustache block helper is a method that acts on the encapsulated block of conte

Here we are calling the method `raw_code` which will be passed the block content as its argument:

def raw_code(sub_context)
code = sub_context.gsub('{', '&#123;').gsub('}', '&#125;').gsub('<', '&lt;').gsub('>', '&gt;')
"<pre><code>#{code}</code></pre>"
module MasterViewAddons
def raw_code(sub_context)
code = sub_context.gsub('{', '&#123;').gsub('}', '&#125;').gsub('<', '&lt;').gsub('>', '&gt;')
"<pre><code>#{code}</code></pre>"
end
end

# now make add the plugin globally available
Ruhoh::Views::MasterView.send(:include, MasterViewAddons)

Block helpers should return a String.

For more information see the [2.x View Helper Plugins upgrade instructions](http://ruhoh.com/docs/2/upgrading/#toc_17).

## Contextual Helpers

A mustache contextual helper is a special kind of block helper that acts on a given context (a data-structure),
Expand Down