Module: PagesHelper
- Defined in:
- app/helpers/pages_helper.rb
Instance Method Summary collapse
- #current_page ⇒ Object
- #current_page_resource ⇒ Object
- #page_path_for(resource_or_page) ⇒ Object
- #page_url_for(resource_or_page) ⇒ Object
- #part(name, opts = {}, &block) ⇒ Object
Instance Method Details
#current_page ⇒ Object
2 3 4 |
# File 'app/helpers/pages_helper.rb', line 2 def current_page @current_page end |
#current_page_resource ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/pages_helper.rb', line 43 def current_page_resource() if current_page && current_page.resourceful? controller.instance_variable_get("@#{current_page.resource_type}") end end |
#page_path_for(resource_or_page) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/pages_helper.rb', line 25 def page_path_for(resource_or_page) page = resource_or_page.is_a?(Page) ? resource_or_page : page_by_resource(resource_or_page) path = page.try(:path) if path.blank? "#not-found" else path.gsub(/:[A-z_]+/) do |seg| meth = seg.gsub(/^:/, "") resource_or_page.send(meth) end end end |
#page_url_for(resource_or_page) ⇒ Object
39 40 41 |
# File 'app/helpers/pages_helper.rb', line 39 def page_url_for(resource_or_page) "#{request.protocol}#{request.host_with_port}#{page_path_for(resource_or_page)}" end |
#part(name, opts = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/pages_helper.rb', line 6 def part(name, opts = {}, &block) if @current_page schema = opts.delete(:schema) || PagePart klass = schema.is_a?(Class) ? schema : "#{schema.to_s.camelize}PagePart".constantize p = klass.where(:name => "#{name}", :page_id => @current_page.id).first p ||= klass.create!(:name => "#{name}", :page_id => @current_page.id) if block_given? capture do block.call(p) end else p end end end |