Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: NoICE/hexcms-rails
base: master
...
head fork: NoICE/hexcms-rails
compare: develop
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+# 0.0.2
+
+- Fixed deprecation warnings regarding ActiveSupport::Concern
+
# 0.0.1
- first version as a gem
View
1  TODO.md
@@ -1 +0,0 @@
-- import tests from the parent project and create a dummy app inside this gem
View
4 app/models/hex/cms/locale.rb
@@ -9,6 +9,7 @@ class Locale
EN = 1
CZ = 2
+ RU = 3
def initialize(locale_id)
raise ArgumentError, "expected valid locale_id" unless self.class.locales.keys.include?(locale_id)
@@ -32,7 +33,8 @@ class << self
def locales
{
CZ => 'CZ',
- EN => 'EN'
+ EN => 'EN',
+ RU => 'RU'
}
end
View
8 doc/todo.md
@@ -0,0 +1,8 @@
+# One shots
+
+- Inherit `locale_id` for `cms_menu` from `cms_page` /bug
+- Import tests from the parent project and create a dummy app inside this gem
+
+# Caching
+
+- refactor the code to allow caching
View
14 lib/hex/cms/box_base.rb
@@ -25,16 +25,12 @@ def self.included(base)
base.scope :ordered, base.order("#{base.table_name}.`priority` DESC")
end
- module InstanceMethods
-
- def set_defaults
- self.cms_section = CmsSection::BOX if self.cms_section.blank?
- end
-
- def name_with_type
- [self.cms_section_name, self.name].join(' - ')
- end
+ def set_defaults
+ self.cms_section = CmsSection::BOX if self.cms_section.blank?
+ end
+ def name_with_type
+ [self.cms_section_name, self.name].join(' - ')
end
end
View
132 lib/hex/cms/cms_controller_base.rb
@@ -21,87 +21,83 @@ def self.included(base)
base.helper_method :fetch_web_description
end
- module InstanceMethods
+ protected
- protected
-
- # Returns string which contains name of the layout to be rendered.
- # Is used by +layout+ Rails helper.
- # By default, it uses @cms_layout.file.
- def fetch_layout
- @cms_layout.file.nil? ? 'application' : @cms_layout.file
- end
+ # Returns string which contains name of the layout to be rendered.
+ # Is used by +layout+ Rails helper.
+ # By default, it uses @cms_layout.file.
+ def fetch_layout
+ @cms_layout.file.nil? ? 'application' : @cms_layout.file
+ end
- # Should return content for meta keywords tag.
- # Returns @cms_page.meta_kw by default.
- def fetch_web_keywords
- return '' if @cms_page.blank?
- @cms_page.meta_kw
- end
+ # Should return content for meta keywords tag.
+ # Returns @cms_page.meta_kw by default.
+ def fetch_web_keywords
+ return '' if @cms_page.blank?
+ @cms_page.meta_kw
+ end
- # Should return content for meta description tag.
- # Returns @cms_page.meta_kw by default.
- def fetch_web_description
- return '' if @cms_page.blank?
- @cms_page.meta_desc
- end
+ # Should return content for meta description tag.
+ # Returns @cms_page.meta_kw by default.
+ def fetch_web_description
+ return '' if @cms_page.blank?
+ @cms_page.meta_desc
+ end
- # Loads the page slug from params.
- # Can do any overrides for special cases as well or compose it
- # based on any conditions may occur.
- def fetch_slug
- # lets find this page
- params[:slug]
- end
+ # Loads the page slug from params.
+ # Can do any overrides for special cases as well or compose it
+ # based on any conditions may occur.
+ def fetch_slug
+ # lets find this page
+ params[:slug]
+ end
- # Loads Cms::Page model with slug loaded from +fetch_slug+
- # and stores it into @cms_page object.
- # Calls +render_404+ if that Cms::Page is not found.
- def load_cms_page
- slug = fetch_slug
- @cms_page = ::Cms::Page.with_slug(slug).with_locale(fetch_locale).first
-
- if @cms_page.blank?
- logger.error "#{self.class}: Cms::Page with slug '#{slug}' doesn't exist!"
- render_404
- return
- end
- end
+ # Loads Cms::Page model with slug loaded from +fetch_slug+
+ # and stores it into @cms_page object.
+ # Calls +render_404+ if that Cms::Page is not found.
+ def load_cms_page
+ slug = fetch_slug
+ @cms_page = ::Cms::Page.with_slug(slug).with_locale(fetch_locale).first
- # Loads Cms::Layout instance which will be used to determine
- # in which layout the currently displayed Cms::Page will be rendered.
- # Uses layout defined in @cms_page instance variable by default.
- def load_cms_layout
- @cms_layout = @cms_page.layout
+ if @cms_page.blank?
+ logger.error "#{self.class}: Cms::Page with slug '#{slug}' doesn't exist!"
+ render_404
+ return
end
+ end
- # Loads Cms::Menu for current page.
- # Page isn't forced to have menu. In that case,
- # @cms_menu instance variable is +nil+ and the CMS doesn't mind.
- # Uses menu associated with the current page by default.
- def load_cms_menu
- @cms_menu = @cms_page.menu
- end
+ # Loads Cms::Layout instance which will be used to determine
+ # in which layout the currently displayed Cms::Page will be rendered.
+ # Uses layout defined in @cms_page instance variable by default.
+ def load_cms_layout
+ @cms_layout = @cms_page.layout
+ end
- public
+ # Loads Cms::Menu for current page.
+ # Page isn't forced to have menu. In that case,
+ # @cms_menu instance variable is +nil+ and the CMS doesn't mind.
+ # Uses menu associated with the current page by default.
+ def load_cms_menu
+ @cms_menu = @cms_page.menu
+ end
- # Special page for 404 error, can be used in the routes
- def show_404
- render_404
- end
+ public
- # This is the frontend for the CMS.
- # It's the default CMS action which should eat all CMS-related related routes.
- # It's task is to proceed CMS layouts and page, load everything that is needed
- # for the layout and render all of it properly.
- def show
- @web_title = @cms_page.meta_title.blank? ? @cms_page.name : @cms_page.meta_title
- @h1_title = @cms_page.h1_title.present? ? @cms_page.h1_title : @web_title
+ # Special page for 404 error, can be used in the routes
+ def show_404
+ render_404
+ end
- # render show action with given layout
- render :template => (@cms_layout.template || "cms/show"), :layout => @cms_layout.file
- end
+ # This is the frontend for the CMS.
+ # It's the default CMS action which should eat all CMS-related related routes.
+ # It's task is to proceed CMS layouts and page, load everything that is needed
+ # for the layout and render all of it properly.
+ def show
+ @web_title = @cms_page.meta_title.blank? ? @cms_page.name : @cms_page.meta_title
+ @h1_title = @cms_page.h1_title.present? ? @cms_page.h1_title : @web_title
+ # render show action with given layout
+ render :template => (@cms_layout.template || "cms/show"), :layout => @cms_layout.file
end
end
View
117 lib/hex/cms/controller_methods.rb
@@ -12,75 +12,72 @@ def self.included(base)
base.helper_method :cms_menu_url
end
- module InstanceMethods
-
- # proxy to the Rails default logger
- def logger
- Rails.logger
- end
+ # proxy to the Rails default logger
+ def logger
+ Rails.logger
+ end
- # gets current menu item
- # from rails request
- # you can override this in article controller for example
- def current_menu
- # if we know @cms_page and it's menu, we are lucky...
- return @cms_page.menu if @cms_page && @cms_page.menu
- return @cms_menu if @cms_menu
+ # gets current menu item
+ # from rails request
+ # you can override this in article controller for example
+ def current_menu
+ # if we know @cms_page and it's menu, we are lucky...
+ return @cms_page.menu if @cms_page && @cms_page.menu
+ return @cms_menu if @cms_menu
- # ... if we don't, we must find other way to get it...
- # that means we must override this method!
- nil
- end
+ # ... if we don't, we must find other way to get it...
+ # that means we must override this method!
+ nil
+ end
- # used when rendering menu... to check if currently rendered item
- # is above (ancestor of) current menu
- def current_menu?(rendered_item)
- return true if cms_menu_path(rendered_item) == request.path
+ # used when rendering menu... to check if currently rendered item
+ # is above (ancestor of) current menu
+ def current_menu?(rendered_item)
+ return true if cms_menu_path(rendered_item) == request.path
- m = self.current_menu
- return false if m.blank?
- rendered_item.is_or_is_ancestor_of?(m) || rendered_item.is_or_is_descendant_of?(m)
- end
+ m = self.current_menu
+ return false if m.blank?
+ rendered_item.is_or_is_ancestor_of?(m) || rendered_item.is_or_is_descendant_of?(m)
+ end
- # returns path for link to given menu item
- # @param [Cms::Menu] item
- # TODO move to Cms::Menu, if possible - url generation should be it's own job..
- # at least it could generate the whole string for eval (because routes aren't recognized within model)
- def cms_menu_path(item, opts = {})
- raise ArgumentError, "cms_menu_path: first parameter - Cms::Menu expected, got #{item.inspect}" unless item.kind_of?(::Cms::Menu)
- tmp, id_provider = item.menu_route_code.split(':')
- if id_provider.blank?
- logger.debug "cms_menu_path: calling #{tmp} via send..."
- send(:"#{tmp}_path", opts)
- else
- # let's get value for this id_provider
- id = item.send(id_provider)
- logger.debug "cms_menu_path: calling #{tmp} via send... with #{id_provider} as parameter (#{id})"
- send(:"#{tmp}_path", id, opts)
- end
+ # returns path for link to given menu item
+ # @param [Cms::Menu] item
+ # TODO move to Cms::Menu, if possible - url generation should be it's own job..
+ # at least it could generate the whole string for eval (because routes aren't recognized within model)
+ def cms_menu_path(item, opts = {})
+ raise ArgumentError, "cms_menu_path: first parameter - Cms::Menu expected, got #{item.inspect}" unless item.kind_of?(::Cms::Menu)
+ tmp, id_provider = item.menu_route_code.split(':')
+ if id_provider.blank?
+ logger.debug "cms_menu_path: calling #{tmp} via send..."
+ send(:"#{tmp}_path", opts)
+ else
+ # let's get value for this id_provider
+ id = item.send(id_provider)
+ logger.debug "cms_menu_path: calling #{tmp} via send... with #{id_provider} as parameter (#{id})"
+ send(:"#{tmp}_path", id, opts)
end
+ end
- def cms_menu_url(item, opts = {})
- raise ArgumentError, "cms_menu_url: first parameter - Cms::Menu expected, got #{item.class.name}" unless item.kind_of?(::Cms::Menu)
- tmp, id_provider = item.menu_route_code.split(':')
- if id_provider.blank?
- logger.debug "cms_menu_url: calling #{tmp} via send..."
- send(:"#{tmp}_url", opts)
- else
- # let's get value for this id_provider
- id = item.send(id_provider)
- logger.debug "cms_menu_url: calling #{tmp} via send... with #{id_provider} as parameter (#{id})"
- send(:"#{tmp}_url", id, opts)
- end
+ def cms_menu_url(item, opts = {})
+ raise ArgumentError, "cms_menu_url: first parameter - Cms::Menu expected, got #{item.class.name}" unless item.kind_of?(::Cms::Menu)
+ tmp, id_provider = item.menu_route_code.split(':')
+ if id_provider.blank?
+ logger.debug "cms_menu_url: calling #{tmp} via send..."
+ send(:"#{tmp}_url", opts)
+ else
+ # let's get value for this id_provider
+ id = item.send(id_provider)
+ logger.debug "cms_menu_url: calling #{tmp} via send... with #{id_provider} as parameter (#{id})"
+ send(:"#{tmp}_url", id, opts)
end
+ end
- # render 404 page from anywhere
- def render_404
- @web_title = t('cms.error404.title')
- respond_to do |format|
- format.html { render :template => '/cms/show_404', :layout => 'application', :status => 404 }
- format.all { render :text => t('cms.error404.title'), :status => 404, :content_type => 'text/html' }
- end
+ # render 404 page from anywhere
+ def render_404
+ @web_title = t('cms.error404.title')
+ respond_to do |format|
+ format.html { render :template => '/cms/show_404', :layout => 'application', :status => 404 }
+ format.all { render :text => t('cms.error404.title'), :status => 404, :content_type => 'text/html' }
end
end
end
View
8 lib/hex/cms/layout_base.rb
@@ -14,13 +14,9 @@ def self.included(base)
base.before_validation :set_defaults
end
-
- module InstanceMethods
-
- def set_defaults
- self.file = 'application' if self.file.blank?
- end
+ def set_defaults
+ self.file = 'application' if self.file.blank?
end
end
View
25 lib/hex/cms/locale_module.rb
@@ -23,6 +23,7 @@ def with_locale(locale)
with_locale_id(locale.id)
end
+ # FIXME deprecated methods, remove them
def locale_cz
where(:locale_id => ::Hex::Cms::Locale::CZ)
end
@@ -31,21 +32,21 @@ def locale_en
where(:locale_id => ::Hex::Cms::Locale::EN)
end
- end
-
- module InstanceMethods
-
- def locale
- return nil unless self.locale_id
- @locale ||= ::Hex::Cms::Locale.new(self.locale_id)
+ def locale_ru
+ where(:locale_id => ::Hex::Cms::Locale::RU)
end
- def locale_id=(locale_id)
- self[:locale_id] = locale_id
- @locale = nil
- locale_id
- end
+ end
+
+ def locale
+ return nil unless self.locale_id
+ @locale ||= ::Hex::Cms::Locale.new(self.locale_id)
+ end
+ def locale_id=(locale_id)
+ self[:locale_id] = locale_id
+ @locale = nil
+ locale_id
end
end
View
66 lib/hex/cms/menu_base.rb
@@ -38,7 +38,7 @@ def self.included(base)
base.after_move :determine_and_save_megaslug
base.after_save :place_in_tree
-
+
# delegates
base.delegate :name, :slug, :desc, :to => :target, :prefix => true, :allow_nil => true
base.delegate :name, :code, :to => :menu_route, :prefix => true
@@ -53,45 +53,41 @@ def with_section(cms_section)
end
- module InstanceMethods
-
- def set_defaults
- self.status_id = ::Hex::Cms::Status::ACTIVE if self.status_id.blank?
- self.cms_section = CmsSection::MENU if self.cms_section.blank?
- end
-
- def derive_target_attrs
- if self.target
- self.name = self.target_name
- self.slug = self.target_slug
- end
- end
+ def set_defaults
+ self.status_id = ::Hex::Cms::Status::ACTIVE if self.status_id.blank?
+ self.cms_section = CmsSection::MENU if self.cms_section.blank?
+ end
- # can be overriden in special cases
- def place_in_tree
- self.move_to_child_of(self.tmp_parent) if !self.tmp_parent.blank? && self.tmp_parent.to_i != self.parent_id
+ def derive_target_attrs
+ if self.target
+ self.name = self.target_name
+ self.slug = self.target_slug
end
+ end
- # megaslug is complicated thing
- # generated from slug of all ancestors
- def determine_megaslug
- # megaslug is regenerated always...
- # gather all ancestors, except for root, and create my megaslug from them (and myself)
- tmp = []
- tmp.concat(self.ancestors.where("#{self.class.table_name}.`parent_id` IS NOT NULL").all.collect(&:slug)) if self.persisted?
- tmp << self.slug
- # update only if the record is changed... we end in infinite loop otherwise! (callback -> save -> callback -> save ...)
- self.megaslug = tmp.compact.join('/')
- true
- end
+ # can be overriden in special cases
+ def place_in_tree
+ self.move_to_child_of(self.tmp_parent) if !self.tmp_parent.blank? && self.tmp_parent.to_i != self.parent_id
+ end
- # generates megaslug and saves it, if required
- def determine_and_save_megaslug
- self.determine_megaslug
- self.update_attribute(:megaslug, self.megaslug) if self.megaslug_changed?
- true
- end
+ # megaslug is complicated thing
+ # generated from slug of all ancestors
+ def determine_megaslug
+ # megaslug is regenerated always...
+ # gather all ancestors, except for root, and create my megaslug from them (and myself)
+ tmp = []
+ tmp.concat(self.ancestors.where("#{self.class.table_name}.`parent_id` IS NOT NULL").all.collect(&:slug)) if self.persisted?
+ tmp << self.slug
+ # update only if the record is changed... we end in infinite loop otherwise! (callback -> save -> callback -> save ...)
+ self.megaslug = tmp.compact.join('/')
+ true
+ end
+ # generates megaslug and saves it, if required
+ def determine_and_save_megaslug
+ self.determine_megaslug
+ self.update_attribute(:megaslug, self.megaslug) if self.megaslug_changed?
+ true
end
end
View
3  lib/hex/cms/menu_route_base.rb
@@ -10,9 +10,6 @@ def self.included(base)
base.has_many :menus, :class_name => "Cms::Menu", :foreign_key => :menu_route_id
end
- module InstanceMethods
- end
-
end
end
end
View
42 lib/hex/cms/page_base.rb
@@ -33,32 +33,28 @@ def self.included(base)
base.delegate :name, :file, :template, :to => :layout, :prefix => true, :allow_nil => true
end
- module InstanceMethods
-
- def set_defaults
- self.status_id = ::Hex::Cms::Status::ACTIVE if self.status_id.blank?
- end
-
- def update_menu
- m = self.menu
- # no menu is attached? just return
- return true if m.blank?
- m.send(:derive_target_attrs)
- m.save!
- end
+ def set_defaults
+ self.status_id = ::Hex::Cms::Status::ACTIVE if self.status_id.blank?
+ end
- # returns first menu associated to this page
- # TODO prioritize the search... i.e. there should be some way
- # how to tell "this is your main menu"
- def menu
- @menu ||= ::Cms::Menu.where(:target_id => self.id, :target_type => self.class.model_name).first
- end
+ def update_menu
+ m = self.menu
+ # no menu is attached? just return
+ return true if m.blank?
+ m.send(:derive_target_attrs)
+ m.save!
+ end
- # returns all boxes with given CmsSection
- def boxes_with_section(cms_section)
- self.boxes.ordered.with_locale_id(self.locale_id).where(:cms_section => cms_section)
- end
+ # returns first menu associated to this page
+ # TODO prioritize the search... i.e. there should be some way
+ # how to tell "this is your main menu"
+ def menu
+ @menu ||= ::Cms::Menu.where(:target_id => self.id, :target_type => self.class.model_name).first
+ end
+ # returns all boxes with given CmsSection
+ def boxes_with_section(cms_section)
+ self.boxes.ordered.with_locale_id(self.locale_id).where(:cms_section => cms_section)
end
end
View
41 lib/hex/cms/status_module.rb
@@ -20,33 +20,30 @@ def with_status(status_id)
end
end
- module InstanceMethods
-
- # returns Status object
- def status
- return nil unless self.status_id
- @status ||= ::Hex::Cms::Status.new(self.status_id)
- end
-
- def status_id=(status_id)
- self[:status_id] = status_id
- @status = nil
- status_id
- end
+ # returns Status object
+ def status
+ return nil unless self.status_id
+ @status ||= ::Hex::Cms::Status.new(self.status_id)
+ end
- def status_active?
- self.status_id == ::Hex::Cms::Status::ACTIVE
- end
+ def status_id=(status_id)
+ self[:status_id] = status_id
+ @status = nil
+ status_id
+ end
- def status_inactive?
- self.status_id == ::Hex::Cms::Status::INACTIVE
- end
+ def status_active?
+ self.status_id == ::Hex::Cms::Status::ACTIVE
+ end
- def status_removed?
- self.status_id == ::Hex::Cms::Status::REMOVED
- end
+ def status_inactive?
+ self.status_id == ::Hex::Cms::Status::INACTIVE
+ end
+ def status_removed?
+ self.status_id == ::Hex::Cms::Status::REMOVED
end
+
end
end
end
View
2  lib/hex/cms/version.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
module Hex
module Cms
- VERSION = "0.0.1"
+ VERSION = "0.0.4"
end
end

No commit comments for this range

Something went wrong with that request. Please try again.