moving files around a bit
Oleg
committed Oct 18, 2010
commit 58444e3268a5197cf55fa0ffcc1a9cfe40eef10f
Showing 21
changed files with
321 additions
and 331 deletions
app/models/cms_upload.rb
+1
-6
| @@ | @@ -27,12 +27,7 @@ class CmsUpload < ActiveRecord::Base |
| end | |
| def icon | |
| - | if self.image? |
| - | self.file.url(:thumb) |
| - | else |
| - | ext = self.file_file_name.split('.').last |
| - | FILE_ICONS.include?(ext) ? "cms/file_icons/#{ext}.png" : "cms/file_icons/_blank.png" |
| - | end |
| + | self.image?? self.file.url(:thumb) : 'TODO' |
| end | |
| end | |
app/views/cms_admin/pages/_form_blocks.html.erb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| <div id='form_blocks'> | |
| - | <%= fields_for :cms_blocks, :builder => CmsFormBuilder do |cms_blocks| %> |
| + | <%= fields_for :cms_blocks, :builder => ComfortableMexicanSofa::FormBuilder do |cms_blocks| %> |
| <% @cms_page.cms_tags(true).each do |tag| %> | |
| <%= cms_blocks.send(tag.class.to_s.underscore.downcase.idify, tag)%> | |
| <% end %> | |
config/initializers/comfortable_mexican_sofa.rb
+3
-3
| @@ | @@ -2,9 +2,9 @@ |
| ComfortableMexicanSofa.configure do |config| | |
| config.cms_title = 'ComfortableMexicanSofa' | |
| - | config.authentication = 'CmsHttpAuthentication' |
| + | config.authentication = 'ComfortableMexicanSofa::HttpAuth' |
| end | |
| # Credentials for CmsHttpAuthentication | |
| - | CmsHttpAuthentication.username = 'username' |
| - | CmsHttpAuthentication.password = 'password' |
| \ No newline at end of file | |
| + | ComfortableMexicanSofa::HttpAuth.username = 'username' |
| + | ComfortableMexicanSofa::HttpAuth.password = 'password' |
| \ No newline at end of file | |
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb
+7
-22
| @@ | @@ -1,13 +1,14 @@ |
| # Loading engine only if this is not a standalone installation | |
| unless defined? ComfortableMexicanSofa::Application | |
| - | require File.expand_path('comfortable_mexican_sofa/cms_engine', File.dirname(__FILE__)) |
| + | require File.expand_path('comfortable_mexican_sofa/engine', File.dirname(__FILE__)) |
| end | |
| - | [ 'comfortable_mexican_sofa/cms_configuration', |
| - | 'comfortable_mexican_sofa/cms_http_authentication', |
| - | 'comfortable_mexican_sofa/cms_rails_extensions', |
| - | 'comfortable_mexican_sofa/cms_form_builder', |
| - | 'comfortable_mexican_sofa/cms_acts_as_tree', |
| + | [ 'comfortable_mexican_sofa/configuration', |
| + | 'comfortable_mexican_sofa/http_auth', |
| + | 'comfortable_mexican_sofa/rails_extensions', |
| + | 'comfortable_mexican_sofa/view_methods', |
| + | 'comfortable_mexican_sofa/form_builder', |
| + | 'comfortable_mexican_sofa/acts_as_tree', |
| '../app/models/cms_block', | |
| '../app/models/cms_snippet', | |
| 'comfortable_mexican_sofa/cms_tag' | |
| @@ | @@ -19,22 +20,6 @@ Dir.glob(File.expand_path('comfortable_mexican_sofa/cms_tag/*.rb', File.dirname( |
| require tag_path | |
| end | |
| - | ActionView::Helpers::AssetTagHelper.register_javascript_expansion :cms => [ |
| - | 'comfortable_mexican_sofa/jquery', |
| - | 'comfortable_mexican_sofa/jquery-ui', |
| - | 'comfortable_mexican_sofa/rails', |
| - | 'comfortable_mexican_sofa/cms', |
| - | 'comfortable_mexican_sofa/plupload/plupload.full.min', |
| - | 'comfortable_mexican_sofa/uploader' |
| - | ] |
| - | ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :cms => [ |
| - | 'comfortable_mexican_sofa/reset', |
| - | 'comfortable_mexican_sofa/structure', |
| - | 'comfortable_mexican_sofa/typography' |
| - | ] |
| - | |
| - | FILE_ICONS = Dir.glob(File.expand_path('public/images/cms/file_icons/*.png', Rails.root)).collect{|f| f.split('/').last.gsub('.png', '')} |
| - | |
| module ComfortableMexicanSofa | |
| class << self | |
comfortable_mexican_sofa/acts_as_tree.rb b/lib/comfortable_mexican_sofa/acts_as_tree.rb
+97
-0
| @@ | @@ -0,0 +1,97 @@ |
| + | module ComfortableMexicanSofa::ActsAsTree |
| + | |
| + | def self.included(base) |
| + | base.extend(ClassMethods) |
| + | end |
| + | |
| + | module ClassMethods |
| + | def acts_as_tree(options = {}) |
| + | configuration = { |
| + | :foreign_key => 'parent_id', |
| + | :order => nil, |
| + | :counter_cache => nil, |
| + | :dependent => :destroy, |
| + | :touch => false } |
| + | configuration.update(options) if options.is_a?(Hash) |
| + | |
| + | belongs_to :parent, |
| + | :class_name => name, |
| + | :foreign_key => configuration[:foreign_key], |
| + | :counter_cache => configuration[:counter_cache], |
| + | :touch => configuration[:touch] |
| + | |
| + | has_many :children, |
| + | :class_name => name, |
| + | :foreign_key => configuration[:foreign_key], |
| + | :order => configuration[:order], |
| + | :dependent => configuration[:dependent] |
| + | |
| + | class_eval <<-EOV |
| + | include ComfortableMexicanSofa::ActsAsTree::InstanceMethods |
| + | |
| + | scope :roots, |
| + | :conditions => "#{configuration[:foreign_key]} IS NULL", |
| + | :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}} |
| + | |
| + | def self.root |
| + | roots.first |
| + | end |
| + | |
| + | validates_each "#{configuration[:foreign_key]}" do |record, attr, value| |
| + | if value |
| + | if record.id == value |
| + | record.errors.add attr, "cannot be it's own id" |
| + | elsif record.descendants.map {|c| c.id}.include?(value) |
| + | record.errors.add attr, "cannot be a descendant's id" |
| + | end |
| + | end |
| + | end |
| + | |
| + | EOV |
| + | end |
| + | end |
| + | |
| + | module InstanceMethods |
| + | # Returns list of ancestors, starting from parent until root. |
| + | # |
| + | # subchild1.ancestors # => [child1, root] |
| + | def ancestors |
| + | node, nodes = self, [] |
| + | nodes << node = node.parent while node.parent |
| + | nodes |
| + | end |
| + | |
| + | # Returns all children and children of children |
| + | def descendants |
| + | nodes = [] |
| + | self.children.each do |c| |
| + | nodes << c |
| + | nodes << c.descendants |
| + | end |
| + | nodes.flatten |
| + | end |
| + | |
| + | # Returns the root node of the tree. |
| + | def root |
| + | node = self |
| + | node = node.parent while node.parent |
| + | node |
| + | end |
| + | |
| + | # Returns all siblings of the current node. |
| + | # |
| + | # subchild1.siblings # => [subchild2] |
| + | def siblings |
| + | self_and_siblings - [self] |
| + | end |
| + | |
| + | # Returns all siblings and a reference to the current node. |
| + | # |
| + | # subchild1.self_and_siblings # => [subchild1, subchild2] |
| + | def self_and_siblings |
| + | parent ? parent.children : self.class.roots |
| + | end |
| + | end |
| + | end |
| + | |
| + | ActiveRecord::Base.send :include, ComfortableMexicanSofa::ActsAsTree |
| \ No newline at end of file | |
comfortable_mexican_sofa/cms_acts_as_tree.rb b/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb
+0
-101
| @@ | @@ -1,101 +0,0 @@ |
| - | module ActiveRecord |
| - | module Acts |
| - | module Tree |
| - | |
| - | def self.included(base) |
| - | base.extend(ClassMethods) |
| - | end |
| - | |
| - | module ClassMethods |
| - | def acts_as_tree(options = {}) |
| - | configuration = { |
| - | :foreign_key => 'parent_id', |
| - | :order => nil, |
| - | :counter_cache => nil, |
| - | :dependent => :destroy, |
| - | :touch => false } |
| - | configuration.update(options) if options.is_a?(Hash) |
| - | |
| - | belongs_to :parent, |
| - | :class_name => name, |
| - | :foreign_key => configuration[:foreign_key], |
| - | :counter_cache => configuration[:counter_cache], |
| - | :touch => configuration[:touch] |
| - | |
| - | has_many :children, |
| - | :class_name => name, |
| - | :foreign_key => configuration[:foreign_key], |
| - | :order => configuration[:order], |
| - | :dependent => configuration[:dependent] |
| - | |
| - | class_eval <<-EOV |
| - | include ActiveRecord::Acts::Tree::InstanceMethods |
| - | |
| - | scope :roots, |
| - | :conditions => "#{configuration[:foreign_key]} IS NULL", |
| - | :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}} |
| - | |
| - | def self.root |
| - | roots.first |
| - | end |
| - | |
| - | validates_each "#{configuration[:foreign_key]}" do |record, attr, value| |
| - | if value |
| - | if record.id == value |
| - | record.errors.add attr, "cannot be it's own id" |
| - | elsif record.descendants.map {|c| c.id}.include?(value) |
| - | record.errors.add attr, "cannot be a descendant's id" |
| - | end |
| - | end |
| - | end |
| - | |
| - | EOV |
| - | end |
| - | end |
| - | |
| - | module InstanceMethods |
| - | # Returns list of ancestors, starting from parent until root. |
| - | # |
| - | # subchild1.ancestors # => [child1, root] |
| - | def ancestors |
| - | node, nodes = self, [] |
| - | nodes << node = node.parent while node.parent |
| - | nodes |
| - | end |
| - | |
| - | # Returns all children and children of children |
| - | def descendants |
| - | nodes = [] |
| - | self.children.each do |c| |
| - | nodes << c |
| - | nodes << c.descendants |
| - | end |
| - | nodes.flatten |
| - | end |
| - | |
| - | # Returns the root node of the tree. |
| - | def root |
| - | node = self |
| - | node = node.parent while node.parent |
| - | node |
| - | end |
| - | |
| - | # Returns all siblings of the current node. |
| - | # |
| - | # subchild1.siblings # => [subchild2] |
| - | def siblings |
| - | self_and_siblings - [self] |
| - | end |
| - | |
| - | # Returns all siblings and a reference to the current node. |
| - | # |
| - | # subchild1.self_and_siblings # => [subchild1, subchild2] |
| - | def self_and_siblings |
| - | parent ? parent.children : self.class.roots |
| - | end |
| - | end |
| - | end |
| - | end |
| - | end |
| - | |
| - | ActiveRecord::Base.send :include, ActiveRecord::Acts::Tree |
| \ No newline at end of file | |
comfortable_mexican_sofa/cms_configuration.rb b/lib/comfortable_mexican_sofa/cms_configuration.rb
+0
-19
| @@ | @@ -1,19 +0,0 @@ |
| - | class ComfortableMexicanSofa::Configuration |
| - | |
| - | # Don't like Comfortable Mexican Sofa? Set it to whatever you like. :( |
| - | attr_accessor :cms_title |
| - | |
| - | # Module that will handle authentication to access cms-admin area |
| - | attr_accessor :authentication |
| - | |
| - | # Enable cms to manage multiple sites |
| - | attr_accessor :multiple_sites |
| - | |
| - | # Configuration defaults |
| - | def initialize |
| - | @cms_title = 'ComfortableMexicanSofa' |
| - | @authentication = 'CmsHttpAuthentication' |
| - | @multiple_sites = false |
| - | end |
| - | |
| - | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/cms_engine.rb b/lib/comfortable_mexican_sofa/cms_engine.rb
+0
-12
| @@ | @@ -1,12 +0,0 @@ |
| - | require 'comfortable_mexican_sofa' |
| - | require 'rails' |
| - | require 'paperclip' |
| - | require 'active_link_to' |
| - | require 'mime/types' |
| - | |
| - | module ComfortableMexicanSofa |
| - | class CMSEngine < ::Rails::Engine |
| - | |
| - | end |
| - | end |
| - | |
comfortable_mexican_sofa/cms_form_builder.rb b/lib/comfortable_mexican_sofa/cms_form_builder.rb
+0
-107
| @@ | @@ -1,107 +0,0 @@ |
| - | class CmsFormBuilder < ActionView::Helpers::FormBuilder |
| - | |
| - | helpers = field_helpers - |
| - | %w(hidden_field fields_for) + |
| - | %w(select) |
| - | |
| - | helpers.each do |name| |
| - | class_eval %Q^ |
| - | def #{name}(field, *args) |
| - | options = args.extract_options! |
| - | args << options |
| - | return super if options.delete(:disable_builder) |
| - | default_field('#{name}', field, options){ super } |
| - | end |
| - | ^ |
| - | end |
| - | |
| - | def default_field(type, field, options = {}, &block) |
| - | %( |
| - | <div class='form_element #{type}_element'> |
| - | <div class='label'>#{label_for(field, options)}</div> |
| - | <div class='value'>#{yield}</div> |
| - | </div> |
| - | ).html_safe |
| - | end |
| - | |
| - | def label_for(field, options) |
| - | label = options.delete(:label) || field.to_s.titleize.capitalize_all |
| - | "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe |
| - | end |
| - | |
| - | def submit(value, options = {}, &block) |
| - | extra_content = @template.capture(&block) if block_given? |
| - | cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : '' |
| - | %( |
| - | <div class='form_element submit_element'> |
| - | #{super(value, options)} #{extra_content} #{cancel_link} |
| - | </div> |
| - | ).html_safe |
| - | end |
| - | |
| - | # -- Tag Field Fields ----------------------------------------------------- |
| - | def default_tag_field(tag, options = {}) |
| - | label = options[:label] || tag.label.to_s.titleize |
| - | css_class = options[:css_class] || tag.class.to_s.underscore.downcase.idify |
| - | |
| - | options[:content_field_method] ||= :text_field_tag |
| - | field = |
| - | options[:field] || |
| - | @template.send(options[:content_field_method], 'cms_page[cms_blocks_attributes][][content]', tag.content, :id => nil) |
| - | |
| - | %( |
| - | <div class='form_element #{css_class}'> |
| - | <div class='label'>#{label}</div> |
| - | <div class='value'> |
| - | #{field} |
| - | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][label]', tag.label)} |
| - | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][type]', tag.type)} |
| - | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][id]', tag.id) unless tag.new_record?} |
| - | </div> |
| - | </div> |
| - | ).html_safe |
| - | end |
| - | |
| - | def field_date_time(tag) |
| - | default_tag_field(tag, :content_field_method => :datetime_field_tag) |
| - | end |
| - | |
| - | def field_integer(tag) |
| - | default_tag_field(tag, :content_field_method => :number_field_tag) |
| - | end |
| - | |
| - | def field_string(tag) |
| - | default_tag_field(tag) |
| - | end |
| - | |
| - | def field_text(tag) |
| - | default_tag_field(tag, :content_field_method => :text_area_tag) |
| - | end |
| - | |
| - | def page_date_time(tag) |
| - | default_tag_field(tag, :content_field_method => :datetime_field_tag) |
| - | end |
| - | |
| - | def page_integer(tag) |
| - | default_tag_field(tag, :content_field_method => :number_field_tag) |
| - | end |
| - | |
| - | def page_string(tag) |
| - | default_tag_field(tag) |
| - | end |
| - | |
| - | def page_text(tag) |
| - | default_tag_field(tag, :content_field_method => :text_area_tag) |
| - | end |
| - | |
| - | # Capturing all calls of cms_tag_* type. For those we'll try to render |
| - | # a form element. Everything else can trigger MethodNotFound error. |
| - | def method_missing(method_name, *args) |
| - | if m = method_name.to_s.match(/^cms_tag_(\w+)$/) |
| - | send(m[1], *args) if respond_to?(m[1]) |
| - | else |
| - | super |
| - | end |
| - | end |
| - | |
| - | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/cms_http_authentication.rb b/lib/comfortable_mexican_sofa/cms_http_authentication.rb
+0
-18
| @@ | @@ -1,18 +0,0 @@ |
| - | module CmsHttpAuthentication |
| - | |
| - | # Set username and password in config/initializers/comfortable_mexican_sofa.rb |
| - | # Like this: |
| - | # CmsHttpAuthentication.username = 'myname' |
| - | # CmsHttpAuthentication.password = 'mypassword' |
| - | mattr_accessor :username, |
| - | :password |
| - | |
| - | # Simple http_auth. When implementing some other form of authentication |
| - | # this method should return +true+ if everything is great, or redirect user |
| - | # to some other page, thus denying access to cms admin section. |
| - | def authenticate |
| - | authenticate_or_request_with_http_basic do |username, password| |
| - | username == self.username && password == self.password |
| - | end |
| - | end |
| - | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/cms_rails_extensions.rb b/lib/comfortable_mexican_sofa/cms_rails_extensions.rb
+0
-32
| @@ | @@ -1,32 +0,0 @@ |
| - | class String |
| - | # Converts string to something suitable to be used as an element id |
| - | def idify |
| - | self.strip.gsub(/\W/, '_').gsub(/\s|^_*|_*$/, '').squeeze('_') |
| - | end |
| - | |
| - | # Capitalize all words in the string |
| - | def capitalize_all(delimiter = ' ') |
| - | self.split(delimiter).collect{|w| w.capitalize }.join(' ') |
| - | end |
| - | end |
| - | |
| - | module CmsViewHelpers |
| - | |
| - | # Wrapper around CmsFormBuilder |
| - | def cms_form_for(record_or_name_or_array, *args, &proc) |
| - | options = args.extract_options! |
| - | form_for(record_or_name_or_array, *(args << options.merge(:builder => CmsFormBuilder)), &proc) |
| - | end |
| - | |
| - | # Wrapper for <span> |
| - | def span_tag(*args) |
| - | content_tag(:span, *args) |
| - | end |
| - | |
| - | # Rails 3.0 doesn't have this helper defined |
| - | def datetime_field_tag(name, value = nil, options = {}) |
| - | text_field_tag(name, value, options.stringify_keys.update('type' => 'datetime')) |
| - | end |
| - | end |
| - | |
| - | ActionView::Base.send :include, CmsViewHelpers |
| \ No newline at end of file | |
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb
+19
-0
| @@ | @@ -0,0 +1,19 @@ |
| + | class ComfortableMexicanSofa::Configuration |
| + | |
| + | # Don't like Comfortable Mexican Sofa? Set it to whatever you like. :( |
| + | attr_accessor :cms_title |
| + | |
| + | # Module that will handle authentication to access cms-admin area |
| + | attr_accessor :authentication |
| + | |
| + | # Enable cms to manage multiple sites |
| + | attr_accessor :multiple_sites |
| + | |
| + | # Configuration defaults |
| + | def initialize |
| + | @cms_title = 'ComfortableMexicanSofa' |
| + | @authentication = 'CmsHttpAuthentication' |
| + | @multiple_sites = false |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/controller_methods.rb b/lib/comfortable_mexican_sofa/controller_methods.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | module ComfortableMexicanSofa::ControllerMethods |
| + | |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/engine.rb b/lib/comfortable_mexican_sofa/engine.rb
+12
-0
| @@ | @@ -0,0 +1,12 @@ |
| + | require 'comfortable_mexican_sofa' |
| + | require 'rails' |
| + | require 'paperclip' |
| + | require 'active_link_to' |
| + | require 'mime/types' |
| + | |
| + | module ComfortableMexicanSofa |
| + | class Engine < ::Rails::Engine |
| + | |
| + | end |
| + | end |
| + | |
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb
+107
-0
| @@ | @@ -0,0 +1,107 @@ |
| + | class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder |
| + | |
| + | helpers = field_helpers - |
| + | %w(hidden_field fields_for) + |
| + | %w(select) |
| + | |
| + | helpers.each do |name| |
| + | class_eval %Q^ |
| + | def #{name}(field, *args) |
| + | options = args.extract_options! |
| + | args << options |
| + | return super if options.delete(:disable_builder) |
| + | default_field('#{name}', field, options){ super } |
| + | end |
| + | ^ |
| + | end |
| + | |
| + | def default_field(type, field, options = {}, &block) |
| + | %( |
| + | <div class='form_element #{type}_element'> |
| + | <div class='label'>#{label_for(field, options)}</div> |
| + | <div class='value'>#{yield}</div> |
| + | </div> |
| + | ).html_safe |
| + | end |
| + | |
| + | def label_for(field, options) |
| + | label = options.delete(:label) || field.to_s.titleize.capitalize_all |
| + | "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe |
| + | end |
| + | |
| + | def submit(value, options = {}, &block) |
| + | extra_content = @template.capture(&block) if block_given? |
| + | cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : '' |
| + | %( |
| + | <div class='form_element submit_element'> |
| + | #{super(value, options)} #{extra_content} #{cancel_link} |
| + | </div> |
| + | ).html_safe |
| + | end |
| + | |
| + | # -- Tag Field Fields ----------------------------------------------------- |
| + | def default_tag_field(tag, options = {}) |
| + | label = options[:label] || tag.label.to_s.titleize |
| + | css_class = options[:css_class] || tag.class.to_s.underscore.downcase.idify |
| + | |
| + | options[:content_field_method] ||= :text_field_tag |
| + | field = |
| + | options[:field] || |
| + | @template.send(options[:content_field_method], 'cms_page[cms_blocks_attributes][][content]', tag.content, :id => nil) |
| + | |
| + | %( |
| + | <div class='form_element #{css_class}'> |
| + | <div class='label'>#{label}</div> |
| + | <div class='value'> |
| + | #{field} |
| + | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][label]', tag.label)} |
| + | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][type]', tag.type)} |
| + | #{@template.hidden_field_tag('cms_page[cms_blocks_attributes][][id]', tag.id) unless tag.new_record?} |
| + | </div> |
| + | </div> |
| + | ).html_safe |
| + | end |
| + | |
| + | def field_date_time(tag) |
| + | default_tag_field(tag, :content_field_method => :datetime_field_tag) |
| + | end |
| + | |
| + | def field_integer(tag) |
| + | default_tag_field(tag, :content_field_method => :number_field_tag) |
| + | end |
| + | |
| + | def field_string(tag) |
| + | default_tag_field(tag) |
| + | end |
| + | |
| + | def field_text(tag) |
| + | default_tag_field(tag, :content_field_method => :text_area_tag) |
| + | end |
| + | |
| + | def page_date_time(tag) |
| + | default_tag_field(tag, :content_field_method => :datetime_field_tag) |
| + | end |
| + | |
| + | def page_integer(tag) |
| + | default_tag_field(tag, :content_field_method => :number_field_tag) |
| + | end |
| + | |
| + | def page_string(tag) |
| + | default_tag_field(tag) |
| + | end |
| + | |
| + | def page_text(tag) |
| + | default_tag_field(tag, :content_field_method => :text_area_tag) |
| + | end |
| + | |
| + | # Capturing all calls of cms_tag_* type. For those we'll try to render |
| + | # a form element. Everything else can trigger MethodNotFound error. |
| + | def method_missing(method_name, *args) |
| + | if m = method_name.to_s.match(/^cms_tag_(\w+)$/) |
| + | send(m[1], *args) if respond_to?(m[1]) |
| + | else |
| + | super |
| + | end |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/http_auth.rb b/lib/comfortable_mexican_sofa/http_auth.rb
+17
-0
| @@ | @@ -0,0 +1,17 @@ |
| + | module ComfortableMexicanSofa::HttpAuth |
| + | # Set username and password in config/initializers/comfortable_mexican_sofa.rb |
| + | # Like this: |
| + | # CmsHttpAuthentication.username = 'myname' |
| + | # CmsHttpAuthentication.password = 'mypassword' |
| + | mattr_accessor :username, |
| + | :password |
| + | |
| + | # Simple http_auth. When implementing some other form of authentication |
| + | # this method should return +true+ if everything is great, or redirect user |
| + | # to some other page, thus denying access to cms admin section. |
| + | def authenticate |
| + | authenticate_or_request_with_http_basic do |username, password| |
| + | username == self.username && password == self.password |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/rails_extensions.rb b/lib/comfortable_mexican_sofa/rails_extensions.rb
+11
-0
| @@ | @@ -0,0 +1,11 @@ |
| + | class String |
| + | # Converts string to something suitable to be used as an element id |
| + | def idify |
| + | self.strip.gsub(/\W/, '_').gsub(/\s|^_*|_*$/, '').squeeze('_') |
| + | end |
| + | |
| + | # Capitalize all words in the string |
| + | def capitalize_all(delimiter = ' ') |
| + | self.split(delimiter).collect{|w| w.capitalize }.join(' ') |
| + | end |
| + | end |
| \ No newline at end of file | |
comfortable_mexican_sofa/view_methods.rb b/lib/comfortable_mexican_sofa/view_methods.rb
+33
-0
| @@ | @@ -0,0 +1,33 @@ |
| + | module ComfortableMexicanSofa::ViewMethods |
| + | # Wrapper around CmsFormBuilder |
| + | def cms_form_for(record_or_name_or_array, *args, &proc) |
| + | options = args.extract_options! |
| + | form_for(record_or_name_or_array, *(args << options.merge(:builder => ComfortableMexicanSofa::FormBuilder)), &proc) |
| + | end |
| + | |
| + | # Wrapper for <span> |
| + | def span_tag(*args) |
| + | content_tag(:span, *args) |
| + | end |
| + | |
| + | # Rails 3.0 doesn't have this helper defined |
| + | def datetime_field_tag(name, value = nil, options = {}) |
| + | text_field_tag(name, value, options.stringify_keys.update('type' => 'datetime')) |
| + | end |
| + | end |
| + | |
| + | ActionView::Base.send :include, ComfortableMexicanSofa::ViewMethods |
| + | |
| + | ActionView::Helpers::AssetTagHelper.register_javascript_expansion :cms => [ |
| + | 'comfortable_mexican_sofa/jquery', |
| + | 'comfortable_mexican_sofa/jquery-ui', |
| + | 'comfortable_mexican_sofa/rails', |
| + | 'comfortable_mexican_sofa/cms', |
| + | 'comfortable_mexican_sofa/plupload/plupload.full.min', |
| + | 'comfortable_mexican_sofa/uploader' |
| + | ] |
| + | ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :cms => [ |
| + | 'comfortable_mexican_sofa/reset', |
| + | 'comfortable_mexican_sofa/structure', |
| + | 'comfortable_mexican_sofa/typography' |
| + | ] |
| \ No newline at end of file | |
test/integration/authentication_test.rb
+4
-4
| @@ | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' |
| class AuthenticationTest < ActionDispatch::IntegrationTest | |
| def test_get_with_unauthorized_access | |
| - | assert_equal 'CmsHttpAuthentication', ComfortableMexicanSofa.config.authentication |
| + | assert_equal 'ComfortableMexicanSofa::HttpAuth', ComfortableMexicanSofa.config.authentication |
| get '/cms-admin/pages' | |
| assert_response :unauthorized | |
| get '/' | |
| @@ | @@ -16,9 +16,9 @@ class AuthenticationTest < ActionDispatch::IntegrationTest |
| end | |
| def test_get_with_changed_default_config | |
| - | assert_equal 'CmsHttpAuthentication', ComfortableMexicanSofa.config.authentication |
| - | CmsHttpAuthentication.username = 'newuser' |
| - | CmsHttpAuthentication.password = 'newpass' |
| + | assert_equal 'ComfortableMexicanSofa::HttpAuth', ComfortableMexicanSofa.config.authentication |
| + | ComfortableMexicanSofa::HttpAuth.username = 'newuser' |
| + | ComfortableMexicanSofa::HttpAuth.password = 'newpass' |
| http_auth :get, '/cms-admin/pages' | |
| assert_response :unauthorized | |
| http_auth :get, '/cms-admin/pages', {}, 'newuser', 'newpass' | |
test/test_helper.rb
+5
-5
| @@ | @@ -10,10 +10,10 @@ class ActiveSupport::TestCase |
| # resetting default configuration | |
| ComfortableMexicanSofa.configure do |config| | |
| config.cms_title = 'ComfortableMexicanSofa' | |
| - | config.authentication = 'CmsHttpAuthentication' |
| + | config.authentication = 'ComfortableMexicanSofa::HttpAuth' |
| end | |
| - | CmsHttpAuthentication.username = 'username' |
| - | CmsHttpAuthentication.password = 'password' |
| + | ComfortableMexicanSofa::HttpAuth.username = 'username' |
| + | ComfortableMexicanSofa::HttpAuth.password = 'password' |
| end | |
| # Example usage: | |
| @@ | @@ -47,8 +47,8 @@ class ActionDispatch::IntegrationTest |
| def setup | |
| host! 'test.host' | |
| - | CmsHttpAuthentication.username = 'username' |
| - | CmsHttpAuthentication.password = 'password' |
| + | ComfortableMexicanSofa::HttpAuth.username = 'username' |
| + | ComfortableMexicanSofa::HttpAuth.password = 'password' |
| end | |
| def http_auth(method, path, options = {}, username = 'username', password = 'password') | |
test/unit/cms_configuration_test.rb
+1
-1
| @@ | @@ -5,7 +5,7 @@ class CmsConfigurationTest < ActiveSupport::TestCase |
| def test_configuration_presense | |
| assert config = ComfortableMexicanSofa.configuration | |
| assert_equal 'ComfortableMexicanSofa', config.cms_title | |
| - | assert_equal 'CmsHttpAuthentication', config.authentication |
| + | assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication |
| end | |
| def test_initialization_overrides | |