Class: Chisel::ViewHelper
- Inherits:
-
Object
- Object
- Chisel::ViewHelper
- Defined in:
- lib/chisel/view_helper.rb
Instance Attribute Summary collapse
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#site_dir ⇒ Object
Returns the value of attribute site_dir.
Instance Method Summary collapse
-
#initialize(site_dir, output_path) ⇒ ViewHelper
constructor
A new instance of ViewHelper.
- #link_to(href, text, options = {}) ⇒ Object
- #link_to_page(page, text, options = {}) ⇒ Object
- #link_to_resource(resource, text, options = {}) ⇒ Object
- #path_to(site_relative_path) ⇒ Object
- #render(view, options = {}) ⇒ Object
Constructor Details
#initialize(site_dir, output_path) ⇒ ViewHelper
Returns a new instance of ViewHelper.
5 6 7 8 9 |
# File 'lib/chisel/view_helper.rb', line 5 def initialize(site_dir, output_path) @site_dir = site_dir @config = @site_dir.config @output_path = output_path end |
Instance Attribute Details
#output_path ⇒ Object
Returns the value of attribute output_path.
3 4 5 |
# File 'lib/chisel/view_helper.rb', line 3 def output_path @output_path end |
#site_dir ⇒ Object
Returns the value of attribute site_dir.
3 4 5 |
# File 'lib/chisel/view_helper.rb', line 3 def site_dir @site_dir end |
Instance Method Details
#link_to(href, text, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chisel/view_helper.rb', line 48 def link_to(href, text, = {}) if [:html] attribute_string = '' [:html].each do |k, v| attribute_string += " #{k}=\"#{v}\"" if LinkAttributes.index(k.to_s.downcase) end end href = href[0..-11] if href.end_with?('index.html') and href != 'index.html' "<a href=\"#{href}\"#{attribute_string}>#{text}</a>" end |
#link_to_page(page, text, options = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/chisel/view_helper.rb', line 37 def link_to_page(page, text, = {}) page_output_path = @site_dir.page_output_path(page, @output_path.dirname) href = page_output_path.relative_path_from(@output_path.dirname).to_s link_to(href, text, ) end |
#link_to_resource(resource, text, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chisel/view_helper.rb', line 19 def link_to_resource(resource, text, = {}) view = [:view] || 'index' view_path = @site_dir.resource_view_output_path(resource, view) href = view_path.relative_path_from(@output_path.dirname).to_s # Initialize the view template template = View.fetch(:resource => resource.resource_type, :view => view, :site_dir => @site_dir) # Compute the output path for this specific resource output_path = @site_dir.resource_view_output_path(resource, view) # Now run the view template against this resource template.run(:output_path => output_path, :resource => resource) link_to(href, text, ) end |
#path_to(site_relative_path) ⇒ Object
44 45 46 |
# File 'lib/chisel/view_helper.rb', line 44 def path_to(site_relative_path) @site_dir.site_relative_path(site_relative_path, @output_path.dirname).relative_path_from(@output_path.dirname) end |