Module: Hyde::Helpers
- Defined in:
- lib/hyde/helpers.rb
Instance Method Summary collapse
- #content_blocks ⇒ Object
-
#content_for(key, &blk) ⇒ Object
Method: content_for (Hyde::Helpers) Content for.
-
#has_content?(key) ⇒ Boolean
Method: has_content? (Hyde::Helpers) Checks if there's something defined for a given content block.
-
#partial(path, locals = {}) ⇒ Object
Method: partial (Hyde::Helpers) Renders a partial.
-
#rel(path) ⇒ Object
Method: rel (Hyde::Helpers) Turns a path into a relative path.
-
#yield_content(key, *args) ⇒ Object
Method: yield_content (Hyde::Helpers) Yield.
Instance Method Details
#content_blocks ⇒ Object
86 87 88 89 |
# File 'lib/hyde/helpers.rb', line 86 def content_blocks $content_blocks ||= Hash.new $content_blocks[page.path] ||= Hash.new end |
#content_for(key, &blk) ⇒ Object
Method: content_for (Hyde::Helpers) Content for.
See also
- has_content?
- content_for
- yield_content
82 83 84 |
# File 'lib/hyde/helpers.rb', line 82 def content_for(key, &blk) content_blocks[key.to_sym] = blk end |
#has_content?(key) ⇒ Boolean
Method: has_content? (Hyde::Helpers) Checks if there's something defined for a given content block.
Example
See content_for for an example.
See also
- has_content?
- content_for
- yield_content
102 103 104 |
# File 'lib/hyde/helpers.rb', line 102 def has_content?(key) content_blocks.member? key.to_sym end |
#partial(path, locals = {}) ⇒ Object
Method: partial (Hyde::Helpers) Renders a partial.
Usage
<%= partial path, locals %>
Description
See Introduction: Partials for more info.
Example
If your _layouts/_banner.erb looks like this:
<div class='banner'>
Welcome to <%= start.title %>
</div>
...Then this will embed the partial _layouts/_nav.erb. The partial
will be rendered with start being set to the current page.
<%= partial '_banner', :start => page %>
36 37 38 39 |
# File 'lib/hyde/helpers.rb', line 36 def partial(path, locals={}) partial = Partial[path.to_s, page] or return '' partial.to_html locals.merge(:page => self) end |
#rel(path) ⇒ Object
Method: rel (Hyde::Helpers) Turns a path into a relative path.
Usage
<%= rel(path) %>
Description
rel takes a given absolute path that begins with a / (for instance,
/x/y/z.html) and returns a relative path (maybe ../y/z.html). This is
useful if your site will not be be hosted on it's own domain.
Example
<% page.children.each do |child| %>
<a href="<%= rel(child.path) %>">
<%= child.title %>
</a>
<% end %>
This may output:
<a href="../../foo.html">
Foobar
</a>
...where the ../../ depends on the current page's path.
67 68 69 70 71 |
# File 'lib/hyde/helpers.rb', line 67 def rel(path) depth = page.path.count('/') dotdot = depth > 1 ? ('../' * (depth-1)) : './' (dotdot[0...-1] + path) end |
#yield_content(key, *args) ⇒ Object
Method: yield_content (Hyde::Helpers) Yield
Example
See content_for for an example.
See also
- has_content?
- content_for
- yield_content
117 118 119 120 121 122 123 124 |
# File 'lib/hyde/helpers.rb', line 117 def yield_content(key, *args) content = content_blocks[key.to_sym] if respond_to?(:block_is_haml?) && block_is_haml?(content) capture_haml(*args, &content) elsif content content.call(*args) end end |