Sha256: b008b44e53e5bbd8e422a74b32ccdfc855a48d314eaa40b51d37ba29fe6495cf
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
module Pageable extend ActiveSupport::Concern included do before_filter :load_current_page end module ClassMethods def page(name, path, options = {}, &block) this_controller_name = "#{self.name.underscore}".gsub("_controller", "") uid = "#{this_controller_name}##{name}" parent_uid = if parent_opt = options.delete(:parent) parent_opt = parent_opt.to_s if parent_opt.include?("#") parent_opt else "#{this_controller_name}##{parent_opt}" end end resource_type = options.delete(:resource).try(:to_s) i18n_scope = "pages.#{self.name.underscore.split('/').last}##{name}" title = options.delete(:title) || I18n.t("#{i18n_scope}.title", :default => "#{name}".humanize) if Page.table_exists? page = Page.find_or_create_by_uid(uid, :title => title, :name => name) if parent_uid parent = Page.find_by_uid(parent_uid) #raise [parent_uid.to_s, parent].inspect page.move_to_child_of(parent) unless page.parent == parent end if resource_type page.update_attribute(:resource_type, resource_type) unless page.resource_type == resource_type end if page.path != path page.update_attribute(:path, path) end end map(name, path, options = {}, &block) @pages ||= [] @pages << "#{name}" end def pages @pages || [] end end def load_current_page if self.class.pages.include?(action_name) this_controller_name = "#{self.class.name.underscore}".gsub("_controller", "") @current_page = Page.find_by_uid("#{this_controller_name}##{action_name}") end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fullstack-cms-0.1.9 | app/models/pageable.rb |
fullstack-cms-0.1.8 | app/models/pageable.rb |
fullstack-cms-0.1.7 | app/models/pageable.rb |