Sha256: 6713925afcd9210b5c7857adbf6fdc77640d7539fe826d49c4c93145a4eeda86
Contents?: true
Size: 1.62 KB
Versions: 34
Compression:
Stored size: 1.62 KB
Contents
module PagesHelper def current_page @current_page end 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 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 def page_url_for(resource_or_page) "#{request.protocol}#{request.host_with_port}#{page_path_for(resource_or_page)}" end def current_page_resource() if current_page && current_page.resourceful? controller.instance_variable_get("@#{current_page.resource_type}") end end def home? request.path == "/" end private def page_by_resource(resource) resource_type = resource.class.name.underscore if Fullstack::Cms.config.localize locale = resource.respond_to?(:locale) ? resource.send(:locale) : I18n.locale.to_s Page.find_by_resource_type_and_locale(resource_type, locale) else Page.find_by_resource_type(resource_type) end end end
Version data entries
34 entries across 34 versions & 1 rubygems