Module: Machined::Helpers::PageHelpers
- Included in:
- Context
- Defined in:
- lib/machined/helpers/page_helpers.rb
Instance Method Summary collapse
-
#context_for(path, environment = self.environment) ⇒ Object
Returns the context of the given path.
-
#layout ⇒ Object
Returns the default layout, unless overridden by the YAML front matter.
-
#title ⇒ Object
Returns the local variable, title, if set.
-
#url ⇒ Object
Returns the URL to this asset, appending the sprocket’s URL.
Instance Method Details
#context_for(path, environment = self.environment) ⇒ Object
Returns the context of the given path. This is useful if you want to get the information from the front matter of a specific page.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/machined/helpers/page_helpers.rb', line 9 def context_for(path, environment = self.environment) pathname = environment.resolve path, :base_path => self.pathname.dirname contexts_cache[pathname] ||= begin if pathname == self.pathname self else depend_on_asset pathname environment.find_asset(pathname).send :dependency_context end end end |
#layout ⇒ Object
Returns the default layout, unless overridden by the YAML front matter.
24 25 26 27 28 29 30 |
# File 'lib/machined/helpers/page_helpers.rb', line 24 def layout if has_local? :layout locals[:layout] else machined.config.layout end end |
#title ⇒ Object
Returns the local variable, title, if set. Otherwise return a titleized version of the filename.
34 35 36 37 38 39 40 |
# File 'lib/machined/helpers/page_helpers.rb', line 34 def title if has_local? :title locals[:title] else File.basename(logical_path).titleize end end |
#url ⇒ Object
Returns the URL to this asset, appending the sprocket’s URL. For HTML files, this will return pretty URLs.
44 45 46 |
# File 'lib/machined/helpers/page_helpers.rb', line 44 def url File.join(environment.config.url, @logical_path).sub /(index)?\.html$/, '' end |