├── app └── models │ ├── .gitkeep │ ├── manageable_content.rb │ └── manageable_content │ ├── page_content.rb │ └── page.rb ├── spec ├── dummy │ ├── log │ │ └── .gitkeep │ ├── app │ │ ├── mailers │ │ │ └── .gitkeep │ │ ├── models │ │ │ └── .gitkeep │ │ ├── views │ │ │ ├── admin │ │ │ │ └── home │ │ │ │ │ └── index.html.erb │ │ │ ├── blog │ │ │ │ └── home │ │ │ │ │ └── index.html.erb │ │ │ ├── static_pages │ │ │ │ └── index.html.erb │ │ │ ├── home │ │ │ │ └── index.html.erb │ │ │ ├── contact │ │ │ │ └── index.html.erb │ │ │ └── layouts │ │ │ │ ├── blog.html.erb │ │ │ │ └── application.html.erb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── controllers │ │ │ ├── blog │ │ │ │ ├── home_controller.rb │ │ │ │ └── application_controller.rb │ │ │ ├── home_controller.rb │ │ │ ├── contact_controller.rb │ │ │ ├── static_pages_controller.rb │ │ │ └── application_controller.rb │ │ └── assets │ │ │ ├── stylesheets │ │ │ └── application.css │ │ │ └── javascripts │ │ │ └── application.js │ ├── lib │ │ └── assets │ │ │ └── .gitkeep │ ├── public │ │ ├── favicon.ico │ │ ├── 422.html │ │ ├── 404.html │ │ └── 500.html │ ├── config.ru │ ├── config │ │ ├── environment.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── initializers │ │ │ ├── manageable_content.rb │ │ │ ├── mime_types.rb │ │ │ ├── inflections.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── session_store.rb │ │ │ ├── wrap_parameters.rb │ │ │ └── secret_token.rb │ │ ├── boot.rb │ │ ├── routes.rb │ │ ├── database.yml │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ │ └── application.rb │ ├── Rakefile │ ├── script │ │ └── rails │ └── db │ │ └── schema.rb ├── lib │ └── manageable_content │ │ ├── version_spec.rb │ │ ├── engine_spec.rb │ │ ├── controllers │ │ └── dsl_spec.rb │ │ └── manager_spec.rb ├── factories │ ├── page.rb │ └── page_content.rb ├── spec_helper.rb ├── models │ └── manageable_content │ │ ├── page_content_spec.rb │ │ └── page_spec.rb └── integration │ └── manageable_content_usage_spec.rb ├── .rspec ├── lib ├── manageable_content │ ├── version.rb │ ├── engine.rb │ ├── controllers │ │ └── dsl.rb │ └── manager.rb ├── manageable_content.rb └── tasks │ └── manageable_content_tasks.rake ├── .gitignore ├── Gemfile ├── .travis.yml ├── script └── rails ├── db └── migrate │ ├── 20110814002730_create_manageable_content_pages.rb │ └── 20110814003912_create_manageable_content_page_contents.rb ├── CHANGELOG.rdoc ├── Rakefile ├── Guardfile ├── MIT-LICENSE ├── manageable_content.gemspec └── README.rdoc /app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/log/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format documentation -------------------------------------------------------------------------------- /spec/dummy/app/views/admin/home/index.html.erb: -------------------------------------------------------------------------------- 1 | Admin/HomeController#index -------------------------------------------------------------------------------- /spec/dummy/app/views/blog/home/index.html.erb: -------------------------------------------------------------------------------- 1 | Blog/HomeController#index -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /lib/manageable_content/version.rb: -------------------------------------------------------------------------------- 1 | module ManageableContent 2 | VERSION = "0.2.6" 3 | end -------------------------------------------------------------------------------- /lib/manageable_content.rb: -------------------------------------------------------------------------------- 1 | require "manageable_content/engine" 2 | 3 | module ManageableContent 4 | end -------------------------------------------------------------------------------- /app/models/manageable_content.rb: -------------------------------------------------------------------------------- 1 | module ManageableContent 2 | def self.table_name_prefix 3 | 'manageable_content_' 4 | end 5 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | *.gem 3 | .bundle/ 4 | log/*.log 5 | pkg/ 6 | spec/dummy/db/*.sqlite3 7 | spec/dummy/log/*.log 8 | spec/dummy/tmp/ -------------------------------------------------------------------------------- /spec/dummy/app/views/static_pages/index.html.erb: -------------------------------------------------------------------------------- 1 | StaticPagesController#index 2 | 3 |
<%= manageable_content_for :body %>
-------------------------------------------------------------------------------- /spec/dummy/app/controllers/blog/home_controller.rb: -------------------------------------------------------------------------------- 1 | class Blog::HomeController < Blog::ApplicationController 2 | 3 | def index 4 | end 5 | 6 | end -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | gemspec 4 | 5 | case ENV['RAILS_VERSION'] 6 | when "3.1"; gem "rails", "~> 3.1.0" 7 | when "3.2"; gem "rails", "~> 3.2.0" 8 | end -------------------------------------------------------------------------------- /spec/dummy/app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | 3 | manageable_content_for :body, :side 4 | 5 | def index 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /spec/dummy/app/views/home/index.html.erb: -------------------------------------------------------------------------------- 1 | HomeController#index 2 | 3 |
<%= manageable_content_for :body %>
4 |
<%= manageable_content_for :side %>
-------------------------------------------------------------------------------- /spec/dummy/app/controllers/contact_controller.rb: -------------------------------------------------------------------------------- 1 | class ContactController < ApplicationController 2 | 3 | manageable_content_for :body, :message 4 | 5 | def index 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Dummy::Application 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | rvm: 2 | - ree 3 | - 1.8.7 4 | - 1.9.2 5 | - 1.9.3 6 | 7 | env: 8 | - RAILS_VERSION=3.1 9 | - RAILS_VERSION=3.2 10 | 11 | script: "bundle exec rake db:migrate spec" -------------------------------------------------------------------------------- /spec/dummy/app/views/contact/index.html.erb: -------------------------------------------------------------------------------- 1 | ContactController#index 2 | 3 |
<%= manageable_content_for :body %>
4 |
<%= manageable_content_for :message %>
-------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /spec/lib/manageable_content/version_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "The Engine Version" do 4 | 5 | it "should be retrievable" do 6 | assert ManageableContent::VERSION 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /spec/factories/page.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :page, :class => ManageableContent::Page do 3 | key 'page-key' 4 | locale { ManageableContent::Engine.config.locales.sample } 5 | end 6 | end -------------------------------------------------------------------------------- /spec/dummy/app/controllers/static_pages_controller.rb: -------------------------------------------------------------------------------- 1 | class StaticPagesController < ApplicationController 2 | 3 | manageable_content_custom_key do 4 | params[:page] 5 | end 6 | 7 | def index 8 | end 9 | 10 | end -------------------------------------------------------------------------------- /spec/factories/page_content.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :page_content, :class => ManageableContent::PageContent do 3 | page 4 | key 'content-key' 5 | content { "The #{page.id} #{key} content" } 6 | end 7 | end -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /spec/lib/manageable_content/engine_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "The Engine" do 4 | 5 | it "should define the table_name_prefix for the engine" do 6 | ManageableContent.table_name_prefix.should == "manageable_content_" 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /spec/dummy/config/initializers/manageable_content.rb: -------------------------------------------------------------------------------- 1 | ManageableContent::Engine.config.locales = [:en, :pt] 2 | ManageableContent::Engine.config.custom_pages = { 3 | "static/page1" => {:body => :text}, 4 | "static/page2" => {:body => :text, :footer => :string} 5 | } -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/blog/application_controller.rb: -------------------------------------------------------------------------------- 1 | class Blog::ApplicationController < ActionController::Base 2 | include ManageableContent::Controllers::Dsl 3 | 4 | protect_from_forgery 5 | layout 'blog' 6 | 7 | manageable_layout_content_for :blog_title, :layout => 'blog' 8 | end 9 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #!/usr/bin/env ruby 3 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 4 | 5 | ENGINE_PATH = File.expand_path('../..', __FILE__) 6 | load File.expand_path('../../spec/dummy/script/rails', __FILE__) -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /spec/dummy/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/blog.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= manageable_layout_content_for :blog_title %> 5 | <%= stylesheet_link_tag "application" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 |

Blog Layout

12 | <%= yield %> 13 | 14 | 15 | -------------------------------------------------------------------------------- /db/migrate/20110814002730_create_manageable_content_pages.rb: -------------------------------------------------------------------------------- 1 | class CreateManageableContentPages < ActiveRecord::Migration 2 | def change 3 | create_table :manageable_content_pages do |t| 4 | t.string :key 5 | t.string :locale 6 | 7 | t.timestamps 8 | end 9 | 10 | add_index :manageable_content_pages, [:key, :locale], :unique => true 11 | end 12 | end -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll automatically include all the stylesheets available in this directory 3 | * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 4 | * the top of the compiled file, but it's generally better to create a new file per style scope. 5 | *= require_self 6 | *= require_tree . 7 | */ -------------------------------------------------------------------------------- /app/models/manageable_content/page_content.rb: -------------------------------------------------------------------------------- 1 | class ManageableContent::PageContent < ActiveRecord::Base 2 | belongs_to :page, :touch => true 3 | 4 | attr_accessible :content 5 | 6 | validates :page_id, :presence => true 7 | validates :key, :presence => true 8 | 9 | default_scope order("#{ActiveRecord::Base.connection.quote_column_name('short')} DESC, #{ActiveRecord::Base.connection.quote_column_name('key')} ASC") 10 | end -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | include ManageableContent::Controllers::Dsl 3 | 4 | protect_from_forgery 5 | 6 | manageable_layout_content_for :footer_contact, :type => :string 7 | manageable_layout_content_for :footer_copyright, :type => :text 8 | 9 | manageable_content_for :title, :type => :string 10 | manageable_content_for :keywords, :type => :text 11 | end 12 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Dummy::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /db/migrate/20110814003912_create_manageable_content_page_contents.rb: -------------------------------------------------------------------------------- 1 | class CreateManageableContentPageContents < ActiveRecord::Migration 2 | def change 3 | create_table :manageable_content_page_contents do |t| 4 | t.references :page 5 | t.string :key 6 | t.boolean :short, :default => false 7 | t.text :content 8 | 9 | t.timestamps 10 | end 11 | 12 | add_index :manageable_content_page_contents, [:page_id, :key], :unique => true 13 | end 14 | end -------------------------------------------------------------------------------- /lib/tasks/manageable_content_tasks.rake: -------------------------------------------------------------------------------- 1 | namespace :manageable_content do 2 | 3 | desc "Generates ManageableContent::Page (check documentation for ManageableContent::Manager.generate!)" 4 | task :generate => :environment do 5 | locales = ManageableContent::Engine.config.locales 6 | puts "Generating pages for locales #{locales}..." 7 | 8 | controllers = ManageableContent::Manager.generate! 9 | 10 | puts controllers.map{ |controller| " #{controller}" }.join("\n") 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActionController::Base.wrap_parameters :format => [:json] 8 | 9 | # Disable root element in JSON by default. 10 | if defined?(ActiveRecord) 11 | ActiveRecord::Base.include_root_in_json = false 12 | end 13 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into including all the files listed below. 2 | // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 3 | // be included in the compiled file accessible from http://example.com/assets/application.js 4 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 5 | // the compiled file. 6 | // 7 | //= require jquery 8 | //= require jquery_ujs 9 | //= require_tree . 10 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= manageable_layout_content_for :title %> <%= manageable_content_for :title %> 5 | <%= stylesheet_link_tag "application" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 |

Application Layout

12 |
<%= manageable_layout_content_for :keywords %> <%= manageable_content_for :keywords %>
13 | <%= yield %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Dummy::Application.config.secret_token = 'af1f3206242894ac6406490207b05cad45664589469f9304589062906858ae9edb7c3635fd393f2becc7ae2010db1fd43b840340c7428556b103a96b415e149b' 8 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | 3 | match "home" => "home#index", :as => 'home' 4 | match "contact" => "contact#index", :as => 'contact' 5 | match "blog" => "blog/home#index", :as => 'blog_home' 6 | match "staticpage1" => "static_pages#index", :defaults => { :page => "static/page1" }, :as => 'staticpage1' 7 | match "staticpage2" => "static_pages#index", :defaults => { :page => "static/page2" }, :as => 'staticpage2' 8 | 9 | match "admin" => "admin/home#index", :as => 'admin_home' 10 | 11 | end 12 | -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /app/models/manageable_content/page.rb: -------------------------------------------------------------------------------- 1 | class ManageableContent::Page < ActiveRecord::Base 2 | validates :locale, :presence => true 3 | 4 | has_many :page_contents, :dependent => :delete_all 5 | 6 | scope :with_contents, lambda { includes(:page_contents).joins(:page_contents) } 7 | 8 | attr_accessible :page_contents_attributes 9 | accepts_nested_attributes_for :page_contents 10 | 11 | # Retrieves a PageContent with the given key. 12 | def page_content(key) 13 | key = key.to_s 14 | page_contents.detect { |page_content| page_content.key == key } 15 | end 16 | 17 | # Retrieves a content with the given key. 18 | def content(key) 19 | page_content(key).try(:content) 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /lib/manageable_content/engine.rb: -------------------------------------------------------------------------------- 1 | require 'rails' 2 | require 'manageable_content/controllers/dsl' 3 | require 'manageable_content/manager' 4 | 5 | module ManageableContent 6 | 7 | def self.table_name_prefix 8 | 'manageable_content_' 9 | end 10 | 11 | class Engine < Rails::Engine 12 | initializer 'manageable_content.setup_locales' do |app| 13 | # Configures the managable locales available for the application. 14 | # This is used while generating pages; So, if the application needs a page version 15 | # for the English and Portuguese locales, the following should be set in an initializer: 16 | # 17 | # ManageableContent::Engine.config.locales = [:en, :pt] 18 | # 19 | config.locales = [app.config.i18n.default_locale] unless config.locales.present? 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /CHANGELOG.rdoc: -------------------------------------------------------------------------------- 1 | == 0.2.6 2 | 3 | * Added support for custom pages 4 | 5 | == 0.2.5 6 | 7 | * Running engine i18n initializer after the application so that we can properly load default_locale 8 | 9 | == 0.2.4 10 | 11 | * Fixed PageContent default_scope to use quote_column_name 12 | 13 | == 0.2.3 14 | 15 | * Added compatibility with Rails 3.2 16 | * Added compatibility with Ruby 1.8.7 17 | 18 | == 0.2.2 19 | 20 | * Fixed Page model class loading 21 | 22 | == 0.2.1 23 | 24 | * Only caches eligible_controllers on ManageableContent::Manager if Rails.configuration.cache_classes is true 25 | 26 | == 0.2.0 27 | 28 | * Rails 3.1 final bump 29 | 30 | == 0.1.1 31 | 32 | * README instructions 33 | 34 | == 0.1.0 35 | 36 | * ManageableContent::Controllers::Dsl 37 | * ManageableContent::Manager 38 | * ManageableContent::Page 39 | * ManageableContent::PageContent -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |

We've been notified about this issue and we'll take a look at it shortly.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | rescue LoadError 5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 6 | end 7 | begin 8 | require 'rdoc/task' 9 | rescue LoadError 10 | require 'rdoc/rdoc' 11 | require 'rake/rdoctask' 12 | RDoc::Task = Rake::RDocTask 13 | end 14 | 15 | RDoc::Task.new(:rdoc) do |rdoc| 16 | rdoc.rdoc_dir = 'rdoc' 17 | rdoc.title = 'ManageableContent' 18 | rdoc.options << '--line-numbers' 19 | rdoc.rdoc_files.include('README.rdoc') 20 | rdoc.rdoc_files.include('CHANGELOG.rdoc') 21 | rdoc.rdoc_files.include('app/**/*.rb') 22 | rdoc.rdoc_files.include('lib/**/*.rb') 23 | end 24 | 25 | APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) 26 | load 'rails/tasks/engine.rake' 27 | 28 | 29 | Bundler::GemHelper.install_tasks 30 | 31 | require 'rspec/core/rake_task' 32 | RSpec::Core::RakeTask.new(:spec) 33 | 34 | task :default => :spec -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard 'bundler' do 2 | watch('Gemfile') 3 | watch(/^.+\.gemspec/) 4 | end 5 | 6 | guard 'rspec', :version => 2, :cli => "--color --format documentation" do 7 | watch(%r{^spec/.+_spec\.rb$}) 8 | watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 9 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 10 | watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } 11 | watch(%r{^spec/support/(.+)\.rb$}) { "spec" } 12 | watch('spec/spec_helper.rb') { "spec" } 13 | watch('config/routes.rb') { "spec/routing" } 14 | watch('app/controllers/application_controller.rb') { "spec/controllers" } 15 | watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } 16 | end 17 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= 'test' 2 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 3 | require 'rspec/rails' 4 | require 'database_cleaner' 5 | require 'shoulda-matchers' 6 | require 'factory_girl' 7 | 8 | ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../') 9 | 10 | Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f } 11 | 12 | FactoryGirl.definition_file_paths = [File.join(ENGINE_RAILS_ROOT, 'spec', 'factories')] 13 | FactoryGirl.find_definitions 14 | 15 | RSpec.configure do |config| 16 | config.mock_with :rspec 17 | config.use_transactional_fixtures = false 18 | config.include Factory::Syntax::Methods 19 | config.include Capybara::DSL, :example_group => { :file_path => /\bspec\/integration\// } 20 | 21 | config.before(:suite) do 22 | DatabaseCleaner.strategy = :transaction 23 | DatabaseCleaner.clean_with(:truncation) 24 | end 25 | 26 | config.before(:each) do 27 | DatabaseCleaner.start 28 | end 29 | 30 | config.after(:each) do 31 | DatabaseCleaner.clean 32 | end 33 | end -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2011 Fabio Kreusch 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Do not compress assets 26 | config.assets.compress = false 27 | end 28 | -------------------------------------------------------------------------------- /manageable_content.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | require "manageable_content/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "manageable_content" 7 | s.version = ManageableContent::VERSION 8 | s.authors = ["Fabio Kreusch"] 9 | s.email = ["fabiokr@gmail.com"] 10 | s.homepage = "https://github.com/fabiokr/manageable_content" 11 | s.summary = "A content management framework for Rails" 12 | s.description = "A content management framework for Rails (compatible with 3.1 and 3.2)" 13 | 14 | s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc", "CHANGELOG.rdoc"] 15 | s.test_files = Dir['spec/**/*'] 16 | 17 | s.add_dependency "rails", "~> 3.1" 18 | 19 | s.add_development_dependency "sqlite3" 20 | s.add_development_dependency "rspec-rails", "~> 2.5" 21 | s.add_development_dependency "shoulda-matchers" 22 | s.add_development_dependency "database_cleaner" 23 | s.add_development_dependency "capybara" 24 | s.add_development_dependency "launchy" 25 | s.add_development_dependency "factory_girl" 26 | 27 | s.add_development_dependency "guard-bundler" 28 | s.add_development_dependency "guard-rspec" 29 | end -------------------------------------------------------------------------------- /spec/models/manageable_content/page_content_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ManageableContent::PageContent do 4 | 5 | context "fields" do 6 | it { should have_db_column(:page_id).of_type(:integer) } 7 | it { should have_db_column(:key).of_type(:string) } 8 | it { should have_db_column(:content).of_type(:text) } 9 | it { should have_db_column(:short).of_type(:boolean) } 10 | it { should have_db_column(:created_at).of_type(:datetime) } 11 | it { should have_db_column(:updated_at).of_type(:datetime) } 12 | 13 | it { should have_db_index([:page_id, :key]).unique(true) } 14 | end 15 | 16 | context "mass assignment" do 17 | it { should allow_mass_assignment_of(:content) } 18 | 19 | it { should_not allow_mass_assignment_of(:key) } 20 | it { should_not allow_mass_assignment_of(:page_id) } 21 | it { should_not allow_mass_assignment_of(:short) } 22 | it { should_not allow_mass_assignment_of(:updated_at) } 23 | it { should_not allow_mass_assignment_of(:created_at) } 24 | end 25 | 26 | context "validations" do 27 | it { should validate_presence_of(:page_id) } 28 | it { should validate_presence_of(:key) } 29 | end 30 | 31 | context "associations" do 32 | it { should belong_to :page } 33 | end 34 | 35 | end -------------------------------------------------------------------------------- /spec/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20110814003912) do 15 | 16 | create_table "manageable_content_page_contents", :force => true do |t| 17 | t.integer "page_id" 18 | t.string "key" 19 | t.boolean "short", :default => false 20 | t.text "content" 21 | t.datetime "created_at" 22 | t.datetime "updated_at" 23 | end 24 | 25 | add_index "manageable_content_page_contents", ["page_id", "key"], :name => "index_manageable_content_page_contents_on_page_id_and_key", :unique => true 26 | 27 | create_table "manageable_content_pages", :force => true do |t| 28 | t.string "key" 29 | t.string "locale" 30 | t.datetime "created_at" 31 | t.datetime "updated_at" 32 | end 33 | 34 | add_index "manageable_content_pages", ["key", "locale"], :name => "index_manageable_content_pages_on_key_and_locale", :unique => true 35 | 36 | end 37 | -------------------------------------------------------------------------------- /spec/models/manageable_content/page_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ManageableContent::Page do 4 | 5 | context "fields" do 6 | it { should have_db_column(:key).of_type(:string) } 7 | it { should have_db_column(:locale).of_type(:string) } 8 | it { should have_db_column(:created_at).of_type(:datetime) } 9 | it { should have_db_column(:updated_at).of_type(:datetime) } 10 | 11 | it { should have_db_index([:key, :locale]).unique(true) } 12 | end 13 | 14 | context "mass assignment" do 15 | it { should allow_mass_assignment_of(:page_contents_attributes) } 16 | 17 | it { should_not allow_mass_assignment_of(:key) } 18 | it { should_not allow_mass_assignment_of(:locale) } 19 | it { should_not allow_mass_assignment_of(:updated_at) } 20 | it { should_not allow_mass_assignment_of(:created_at) } 21 | 22 | it { should allow_mass_assignment_of(:page_contents_attributes) } 23 | end 24 | 25 | context "validations" do 26 | it { should validate_presence_of(:locale) } 27 | end 28 | 29 | context "associations" do 30 | it { should have_many(:page_contents) } 31 | end 32 | 33 | context "instance methods" do 34 | before :each do 35 | @page = create(:page, :key => 'the/example', :locale => I18n.locale) 36 | @page_content = create(:page_content, :page => @page, :key => 'mycontent') 37 | end 38 | 39 | it "should retrieve correct content with :page_content" do 40 | @page.page_content(:mycontent).should == @page_content 41 | end 42 | 43 | it "should retrieve correct content with :content" do 44 | @page.content(:mycontent).should == @page_content.content 45 | end 46 | end 47 | end -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Use SQL instead of Active Record's schema dumper when creating the test database. 33 | # This is necessary if your schema can't be completely dumped by the schema dumper, 34 | # like if you have constraints or database-specific column types 35 | # config.active_record.schema_format = :sql 36 | 37 | # Print deprecation notices to the stderr 38 | config.active_support.deprecation = :stderr 39 | end 40 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_mailer/railtie" 7 | require "active_resource/railtie" 8 | require "sprockets/railtie" 9 | # require "rails/test_unit/railtie" 10 | 11 | Bundler.require 12 | require "manageable_content" 13 | 14 | module Dummy 15 | class Application < Rails::Application 16 | # Settings in config/environments/* take precedence over those specified here. 17 | # Application configuration should go into files in config/initializers 18 | # -- all .rb files in that directory are automatically loaded. 19 | 20 | # Custom directories with classes and modules you want to be autoloadable. 21 | # config.autoload_paths += %W(#{config.root}/extras) 22 | 23 | # Only load the plugins named here, in the order given (default is alphabetical). 24 | # :all can be used as a placeholder for all plugins not explicitly named. 25 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 26 | 27 | # Activate observers that should always be running. 28 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 29 | 30 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 31 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 32 | # config.time_zone = 'Central Time (US & Canada)' 33 | 34 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 35 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 36 | # config.i18n.default_locale = :de 37 | 38 | # Configure the default encoding used in templates for Ruby 1.9. 39 | config.encoding = "utf-8" 40 | 41 | # Configure sensitive parameters which will be filtered from the log file. 42 | config.filter_parameters += [:password] 43 | 44 | # Enable the asset pipeline 45 | config.assets.enabled = true 46 | end 47 | end 48 | 49 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Specifies the header that your server uses for sending files 18 | # (comment out if your front-end server doesn't support this) 19 | config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx 20 | 21 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 22 | # config.force_ssl = true 23 | 24 | # See everything in the log (default is :info) 25 | # config.log_level = :debug 26 | 27 | # Use a different logger for distributed setups 28 | # config.logger = SyslogLogger.new 29 | 30 | # Use a different cache store in production 31 | # config.cache_store = :mem_cache_store 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 34 | # config.action_controller.asset_host = "http://assets.example.com" 35 | 36 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 37 | # config.assets.precompile += %w( search.js ) 38 | 39 | # Disable delivery errors, bad email addresses will be ignored 40 | # config.action_mailer.raise_delivery_errors = false 41 | 42 | # Enable threaded mode 43 | # config.threadsafe! 44 | 45 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 46 | # the I18n.default_locale when a translation can not be found) 47 | config.i18n.fallbacks = true 48 | 49 | # Send deprecation notices to registered listeners 50 | config.active_support.deprecation = :notify 51 | end 52 | -------------------------------------------------------------------------------- /spec/integration/manageable_content_usage_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "The demo application" do 4 | context "with manageable content" do 5 | before :each do 6 | ManageableContent::Manager.generate! 7 | 8 | # Application layout 9 | page = ManageableContent::Manager.page('application').first 10 | page.page_content(:title).update_attributes(:content => "Application Title Content") 11 | page.page_content(:keywords).update_attributes(:content => "Application Keywords Content") 12 | page.page_content(:footer_copyright).update_attributes(:content => "Application Footer Copyright Content") 13 | page.page_content(:footer_contact).update_attributes(:content => "Application Footer Contact Content") 14 | 15 | # Blog layout 16 | page = ManageableContent::Manager.page('blog').first 17 | page.page_content(:blog_title).update_attributes(:content => "Blog Application Blog Title Content") 18 | 19 | # Home controller 20 | page = ManageableContent::Manager.page('home').first 21 | page.page_content(:title).update_attributes(:content => "Home Title Content") 22 | page.page_content(:keywords).update_attributes(:content => "Home Keywords Content") 23 | page.page_content(:body).update_attributes(:content => "Home Body Content") 24 | page.page_content(:side).update_attributes(:content => "Home Side Content") 25 | 26 | # Contact controller 27 | page = ManageableContent::Manager.page('contact').first 28 | page.page_content(:title).update_attributes(:content => "Contact Title Content") 29 | page.page_content(:keywords).update_attributes(:content => "Contact Keywords Content") 30 | page.page_content(:body).update_attributes(:content => "Contact Body Content") 31 | page.page_content(:message).update_attributes(:content => "Contact Message Content") 32 | 33 | # StaticPages controller 34 | page = ManageableContent::Manager.page('static/page1').first 35 | page.page_content(:body).update_attributes(:content => "Static Page 1 Body Content") 36 | 37 | page = ManageableContent::Manager.page('static/page2').first 38 | page.page_content(:body).update_attributes(:content => "Static Page 2 Body Content") 39 | 40 | # Blog Home controller 41 | page = ManageableContent::Manager.page('blog/home').first 42 | end 43 | 44 | context "home#index" do 45 | it "should show correct home contents" do 46 | visit home_path 47 | 48 | within "title" do 49 | page.should have_content("Application Title Content Home Title Content") 50 | end 51 | 52 | within "#keywords" do 53 | page.should have_content("Application Keywords Content Home Keywords Content") 54 | end 55 | 56 | within "#body" do 57 | page.should have_content("Home Body Content") 58 | end 59 | 60 | within "#side" do 61 | page.should have_content("Home Side Content") 62 | end 63 | end 64 | end 65 | 66 | context "contact#index" do 67 | it "should show correct contact contents" do 68 | visit contact_path 69 | 70 | within "title" do 71 | page.should have_content("Application Title Content Contact Title Content") 72 | end 73 | 74 | within "#keywords" do 75 | page.should have_content("Application Keywords Content Contact Keywords Content") 76 | end 77 | 78 | within "#body" do 79 | page.should have_content("Contact Body Content") 80 | end 81 | 82 | within "#message" do 83 | page.should have_content("Contact Message Content") 84 | end 85 | end 86 | end 87 | 88 | context "static_pages#index" do 89 | context "static/page1" do 90 | it "should show correct static/page1 contents" do 91 | visit staticpage1_path 92 | 93 | within "#body" do 94 | page.should have_content("Static Page 1 Body Content") 95 | end 96 | end 97 | end 98 | 99 | context "static/page2" do 100 | it "should show correct static/page2 contents" do 101 | visit staticpage2_path 102 | 103 | within "#body" do 104 | page.should have_content("Static Page 2 Body Content") 105 | end 106 | end 107 | end 108 | end 109 | 110 | context "blog#index" do 111 | it "should show correct blog contents" do 112 | visit blog_home_path 113 | 114 | within "title" do 115 | page.should have_content("Blog Application Blog Title Content") 116 | end 117 | end 118 | end 119 | end 120 | 121 | end -------------------------------------------------------------------------------- /lib/manageable_content/controllers/dsl.rb: -------------------------------------------------------------------------------- 1 | module ManageableContent 2 | module Controllers 3 | module Dsl 4 | extend ActiveSupport::Concern 5 | 6 | mattr_accessor :manageable_layout_content_keys 7 | self.manageable_layout_content_keys = {} 8 | 9 | included do 10 | class_attribute :manageable_content_custom_key_evaluator 11 | class_attribute :manageable_content_keys 12 | self.manageable_content_keys = {} 13 | 14 | helper_method :manageable_layout_content_for 15 | helper_method :manageable_content_for 16 | end 17 | 18 | module ClassMethods 19 | 20 | # Configures the manageable contents that will be shared between all Controllers that 21 | # use a given layout. 22 | # For example, if all Controllers using the application layout will share a 'footer_message' 23 | # and a 'footer_copyright' contents, the following should be set: 24 | # 25 | # manageable_layout_content_for :footer_message, :footer_copyright 26 | # 27 | # By default, this will set contents for a layout named the same as the Controller in which 28 | # the manageable_layout_content_for method was called. For example, if it was called in 29 | # the ApplicationController, it will set the layout vars for the 'application' layout. 30 | # If you need to use multiple layouts with ApplicationController, you can specify 31 | # for which layout are the contents being set with this: 32 | # 33 | # manageable_layout_content_for :footer_message, :footer_copyright, :layout => 'application' 34 | # 35 | # You can also set a content type for the given keys. By default they are :text content types. 36 | # Available types are :text for long contents and :string for short contents. 37 | # 38 | # manageable_layout_content_for :footer_copyright, :type => :string 39 | # 40 | def manageable_layout_content_for(*keys) 41 | options = keys.last.is_a?(Hash) ? keys.pop : {} 42 | layout = options[:layout] || self.controller_path 43 | type = options[:type] || :text 44 | 45 | if keys.present? 46 | Dsl.manageable_layout_content_keys[layout] = 47 | ((Dsl.manageable_layout_content_keys[layout] || {}).merge(keys_for_type(type, keys))) 48 | end 49 | end 50 | 51 | # Configures the manageable contents for a Controller. 52 | # For example, if the Controller will have a 'body' and a 'side' contents, 53 | # the following should be set: 54 | # 55 | # manageable_content_for :body, :side 56 | # 57 | # This will also inherit manageable contents from superclasses. For example, 58 | # if all your Controllers will have a 'title' content, you can add the following 59 | # to ApplicationController, and all Controllers which inherit from it will have it too: 60 | # 61 | # manageable_content_for :title 62 | # 63 | # You can also set a content type for the given keys. By default they are :text content types. 64 | # Available types are :text for long contents and :string for short contents. 65 | # 66 | # manageable_content_for :title, :type => :string 67 | # 68 | def manageable_content_for(*keys) 69 | options = keys.last.is_a?(Hash) ? keys.pop : {} 70 | type = options[:type] || :text 71 | 72 | if keys.present? 73 | self.manageable_content_keys = (self.manageable_content_keys.merge(keys_for_type(type, keys))) 74 | end 75 | end 76 | 77 | # Defines a custom page key that should be looked at for valid pages for the current controller. 78 | # This can be useful when dealing with custom pages. 79 | # Expects a block that should return a page key. 80 | # E.g.: 81 | # 82 | # manageable_content_page_key do |params| 83 | # params[:page] 84 | # end 85 | def manageable_content_custom_key(&block) 86 | raise ArgumentError, "Block required" unless block_given? 87 | self.manageable_content_custom_key_evaluator = block 88 | end 89 | 90 | private 91 | 92 | def keys_for_type(type, keys) 93 | keys.inject({}) do |config, key| 94 | config[key] = type 95 | config 96 | end 97 | end 98 | end 99 | 100 | # Retrieves the content for the current layout with a given key. 101 | def manageable_layout_content_for(key) 102 | manageable_content_for_page :layout, key 103 | end 104 | 105 | # Retrieves the content for the current page with a given key. 106 | def manageable_content_for(key) 107 | manageable_content_for_page :controller, key 108 | end 109 | 110 | private 111 | 112 | def manageable_content_for_page(type, key) 113 | layout = if _layout.instance_of? String 114 | # Rails <= 3.1 115 | _layout 116 | else 117 | # Rails >= 3.2 returns something like "layout/application", so we get everything but the 118 | # "layout" part 119 | _layout.virtual_path.split('/')[(1..-1)].join('/') 120 | end 121 | 122 | keys = [layout] 123 | keys << if self.class.manageable_content_custom_key_evaluator 124 | instance_eval(&self.class.manageable_content_custom_key_evaluator) 125 | else 126 | controller_path 127 | end 128 | 129 | @pages ||= ManageableContent::Manager.page(keys) 130 | 131 | subject = type == :layout ? @pages.try(:slice, 0) : @pages.try(:slice, 1) 132 | subject.try(:content, key).try(:html_safe) 133 | end 134 | end 135 | end 136 | end -------------------------------------------------------------------------------- /lib/manageable_content/manager.rb: -------------------------------------------------------------------------------- 1 | module ManageableContent 2 | class Manager 3 | 4 | # Retrieves a list of Controllers eligible for having manageable content. 5 | # A Controller is eligible if it has set contents with :manageable_content_for. 6 | # This method is cached if Rails.configuration.cache_classes is true. 7 | def self.eligible_controllers 8 | if Rails.configuration.cache_classes 9 | @@eligible_controllers ||= find_eligible_controllers 10 | else 11 | find_eligible_controllers 12 | end 13 | end 14 | 15 | # Retrieves a list of custom pages eligible for having manageable content. 16 | # A page is eligible if it is configured on ManageableContent::Engine.config.custom_pages. 17 | # This method is cached if Rails.configuration.cache_classes is true. 18 | def self.eligible_custom 19 | if Rails.configuration.cache_classes 20 | @@eligible_custom ||= ManageableContent::Engine.config.custom_pages.keys.sort 21 | else 22 | ManageableContent::Engine.config.custom_pages.keys.sort 23 | end 24 | end 25 | 26 | # Generates a Page and PageContent for each Controller or custom page with manageable content keys, 27 | # and the layout Page for manageable layout content keys. 28 | # Custom pages can be defined within an initializer with the following code: 29 | # 30 | # ManageableContent::Engine.config.custom_pages = { 31 | # "static/page1" => [:body], 32 | # "static/page2" => [:body, :footer] 33 | # } 34 | def self.generate! 35 | controllers = eligible_controllers 36 | 37 | Engine.config.locales.each do |locale| 38 | # layout page 39 | Controllers::Dsl.manageable_layout_content_keys.each_key do |layout| 40 | generate_page! layout, 41 | locale, 42 | Controllers::Dsl.manageable_layout_content_keys[layout] 43 | end 44 | 45 | # controllers pages 46 | controllers.each do |controller_class| 47 | generate_page! controller_class.controller_path, 48 | locale, 49 | controller_class.manageable_content_keys 50 | end 51 | 52 | # custom pages 53 | ManageableContent::Engine.config.custom_pages.each do |custom_page, content_keys| 54 | generate_page! custom_page, 55 | locale, 56 | content_keys 57 | end 58 | end 59 | 60 | controllers 61 | end 62 | 63 | # Retrieves a Page relation with a filter for eligible Pages. 64 | # A Page is eligible if the corresponding controller is still eligible 65 | # (from the eligible_controllers method). 66 | # 67 | # This method should be used to access a list of valid Pages instead of directly accessing the 68 | # Page model. 69 | def self.pages 70 | eligible_keys = eligible_controllers.map {|controller_class| controller_class.controller_path } + 71 | eligible_custom 72 | 73 | Page.where(:key => eligible_keys) 74 | end 75 | 76 | # Retrieves a Page relation for the given key and locale. 77 | # By default I18n.locale is used as the locale option. 78 | def self.page(key, locale = I18n.locale) 79 | Page.with_contents.where(:key => key, :locale => locale) 80 | end 81 | 82 | # Retrieves a list of eligible keys for a given Page key. 83 | # This can be useful to check if a PageContent is still relevant 84 | # based on the current configurations. 85 | # 86 | # This will return a list of page keys with it's corresponding content type (:string or :text). 87 | def self.eligible_contents(key) 88 | layout_content_keys = Controllers::Dsl.manageable_layout_content_keys[key] || {} 89 | content_keys = begin 90 | "#{key.camelize}Controller".constantize.manageable_content_keys 91 | rescue NameError 92 | ManageableContent::Engine.config.custom_pages[key] || {} 93 | end 94 | 95 | layout_content_keys.merge(content_keys) 96 | end 97 | 98 | protected 99 | 100 | # Retrieves a list of Controllers eligible for having manageable content. 101 | # A Controller is eligible if it has set contents with :manageable_content_for. 102 | def self.find_eligible_controllers 103 | controllers.uniq.select do |controller_class| 104 | controller_class.respond_to?(:manageable_content_keys) && 105 | controller_class.manageable_content_keys.present? && 106 | controller_class.manageable_content_custom_key_evaluator.nil? 107 | end.sort do |controller_a, controller_b| 108 | controller_a.name <=> controller_b.name 109 | end 110 | end 111 | 112 | # Generates a Page and PageContent for the given key, locale and content keys. 113 | def self.generate_page!(key, locale, content_keys) 114 | Rails.logger.info "Generating ManageableContent::Page for key '#{key}', 115 | locale '#{locale}' and keys [#{content_keys.keys.join(',')}]" 116 | 117 | Page.transaction do 118 | page = Manager.page(key, locale).first || Page.new 119 | 120 | if page.new_record? 121 | page.key = key 122 | page.locale = locale 123 | page.save! 124 | end 125 | 126 | content_keys.each do |content_key, content_type| 127 | page_content = page.page_content(content_key) || page.page_contents.build 128 | page_content.key = content_key 129 | page_content.short = content_type == :string 130 | end 131 | 132 | page.save! 133 | end 134 | end 135 | 136 | def self.controllers 137 | Rails.configuration.paths["app/controllers"].expanded.inject([]) do |controllers, dir| 138 | controllers += Dir["#{dir}/**/*_controller.rb"].map do |file| 139 | file.gsub("#{dir}/", "").gsub(".rb", "").camelize.constantize 140 | end 141 | end 142 | end 143 | end 144 | end -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = ManageableContent {Build Status}[http://travis-ci.org/fabiokr/manageable_content] 2 | 3 | Manageable Content is a Rails 3.1 Engine that provides a simple framework for content management. It works by providing a Page instance for each of your configured controllers, so that each controller can have it's own contents that will be available to the views. You can also have shared contents. 4 | 5 | == Contributing 6 | 7 | This engine is a work in progress and open for contributions! Please don't forget to add tests if you plan on contributing. 8 | 9 | == Installation 10 | 11 | This gem is compatible with Rails 3.1. To install it, add the following to your Gemfile: 12 | 13 | gem 'manageable_content' 14 | 15 | After that, run the 'bundle' command to install the gem. 16 | 17 | The next step is to import the engine migrations to your application. Just run this: 18 | 19 | bundle exec rake manageable_content_engine:install:migrations 20 | 21 | Then migrate your database with the usual command: 22 | 23 | bundle exec rake db:migrate 24 | 25 | The last step is to include the Dsl in where you want to make the ManageableContent engine available. For example, you might want to add the following code to your ApplicationController: 26 | 27 | include ManageableContent::Controllers::Dsl 28 | 29 | == Getting Started 30 | 31 | ManageableContent supports two types of contents: a controller content, and a layout content. 32 | A controller content is a content that each controller will have by its own. For example, you might want to have a 'body' content, in which each controller will have a different value for it. 33 | A layout content is a content that will be shared between controllers. For example, you might want to have a 'footer' content that will be shared accross all of your controllers. 34 | 35 | === Controller contents 36 | 37 | Supposing that you have a controller named ContactController and you want it to have its own 'body' content. You will need to add this to the controller code: 38 | 39 | manageable_content_for :body 40 | 41 | After that, run the following rake task: 42 | 43 | bundle exec rake manageable_content:generate 44 | 45 | This rake task will check your controllers configurations and will generate the corresponding pages for each controller with their contents. This should be run everytime a new controller or page content is added. This rake task just calls the ManageableContent::Manager.generate! method. You might want to add some kind of hook so that when you deploy your application the generator will run. 46 | 47 | You might also want to have an administration interface to edit you pages contents. Currently, this engine does not provide that, but you can check an admin example here: https://github.com/fabiokr/manageable_content_example_app/ 48 | 49 | Now, to use this in your views, you have to use the manageable_content_for helper: 50 | 51 | manageable_content_for :body 52 | 53 | This will print the content 'body' for the current controller, if it exists. This will print the content with html_safe. 54 | 55 | If you need a content that all your controllers will have (for example, a 'title' content), you can add the configuration to your parent controller and all controllers that inherit from it will also have that content. For example, you could add this to your ApplicationController: 56 | 57 | manageable_content_for :title 58 | 59 | === Custom contents 60 | 61 | If you need custom pages that are not directly controller related, you can configure them using an initializer: 62 | 63 | ManageableContent::Engine.config.custom_pages = { 64 | "static/page1" => {:body => :text}, 65 | "static/page2" => {:body => :text, :footer => :string} 66 | } 67 | 68 | This work in the same way as controller pages. The example above would create two pages with the keys 69 | "static/page1" and "static/page2" respectivelly. 70 | 71 | To be able to use the helpers to retrieve the content, the controller responsible for the static pages 72 | has to tell manageable_content what page key it will be looking for. You can do that with the following code: 73 | 74 | manageable_content_custom_key do 75 | params[:page] 76 | end 77 | 78 | This will use the params[:page] as the page key to be used by the manageable_content_for helper. 79 | 80 | === Layout contents 81 | 82 | Supposing that your application will have a 'footer' content that should be the same in all of your controllers, you would add this to your ApplicationController: 83 | 84 | manageable_layout_content_for :footer 85 | 86 | In the views, to print it you need to use the manageable_layout_content_for helper: 87 | 88 | manageable_layout_content_for :footer 89 | 90 | ==== Different layouts 91 | 92 | In the previous example, the 'footer' content is available under the 'application' page. By default, manageable_layout_content_for uses the current controller default layout, which in the ApplicationController case is 'application'. 93 | If you need to add a content to a different layout, you could use this: 94 | 95 | manageable_layout_content_for :footer, :layout => 'my_custom_layout' 96 | 97 | === I18n 98 | 99 | If you need different contents for multiple locales, you can generate multiple pages for each available locale. You just need to set the available locales for ManageableContent, and then when you run the generator task it will generate contents for all available locales. To do that, just add an initializer with this content: 100 | 101 | ManageableContent::Engine.config.locales = [:en, :pt] 102 | 103 | By default, this will be set as the same as your application config.i18n.default_locale. 104 | 105 | In your views, the helper calls will remain the same. The helpers use I18n.locale to get the current locale and than will use the content available for that locale. 106 | 107 | === Specs 108 | 109 | To run the specs, first you need to setup the dummy application database and clone it for the test environment: 110 | 111 | rake app:db:schema:load 112 | rake app:db:test:clone 113 | 114 | Now you can run the specs with this: 115 | 116 | rake spec 117 | 118 | == Contributors 119 | 120 | https://github.com/fabiokr/manageable_content/contributors 121 | 122 | == Maintainers 123 | 124 | * Fabio Kreusch (https://github.com/fabiokr) 125 | 126 | == License 127 | 128 | MIT License. Copyright 2011 Fabio Kreusch http://www.kreusch.com.br -------------------------------------------------------------------------------- /spec/lib/manageable_content/controllers/dsl_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "The Controller Dsl" do 4 | 5 | context "class methods" do 6 | 7 | context "manageable_layout_content_for" do 8 | it "should configure the layout content keys for layout" do 9 | ManageableContent::Controllers::Dsl.manageable_layout_content_keys['application'].should == 10 | {:footer_copyright => :text, :footer_contact => :string} 11 | 12 | ManageableContent::Controllers::Dsl.manageable_layout_content_keys['blog'].should == 13 | {:blog_title => :text} 14 | end 15 | end 16 | 17 | context "manageable_content_for" do 18 | it "should configure the content keys for the HomeController" do 19 | HomeController.manageable_content_keys.should == { 20 | :title => :string, :keywords => :text, 21 | :body => :text, :side => :text 22 | } 23 | end 24 | it "should configure the content keys for the ContactController" do 25 | ContactController.manageable_content_keys.should == { 26 | :title => :string, :keywords => :text, 27 | :body => :text, :message => :text 28 | } 29 | end 30 | end 31 | 32 | context "manageable_content_custom_key" do 33 | it "should configure the custom key evaluator for the StaticPagesController" do 34 | StaticPagesController.manageable_content_custom_key_evaluator.should_not be_nil 35 | end 36 | end 37 | end 38 | 39 | context "instance methods" do 40 | context "for controller instances with configured pages" do 41 | before :each do 42 | # Application Layout Contents 43 | @application_layout_page = create(:page, :key => 'application', :locale => I18n.locale) 44 | @application_layout_footer_copyright_content = create(:page_content, 45 | :page => @application_layout_page, :key => "footer_copyright") 46 | @application_layout_footer_contact_content = create(:page_content, 47 | :page => @application_layout_page, :key => "footer_contact") 48 | 49 | # Blog Layout Contents 50 | @blog_layout_page = create(:page, :key => 'blog', :locale => I18n.locale) 51 | @blog_layout_title_content = create(:page_content, 52 | :page => @blog_layout_page, :key => "blog_title") 53 | 54 | # HomeController 55 | @home_controller = HomeController.new 56 | @home_page = create(:page, :key => @home_controller.controller_path, :locale => I18n.locale) 57 | @home_body_content = create(:page_content, :page => @home_page, :key => "body") 58 | @home_side_content = create(:page_content, :page => @home_page, :key => "side") 59 | 60 | # ContactController 61 | @contact_controller = ContactController.new 62 | @contact_page = create(:page, :key => @contact_controller.controller_path, :locale => I18n.locale) 63 | @contact_body_content = create(:page_content, :page => @contact_page, :key => "body") 64 | @contact_message_content = create(:page_content, :page => @contact_page, :key => "message") 65 | 66 | # StaticPagesController 67 | @static_pages_controller = StaticPagesController.new 68 | 69 | @static_page_1_page = create(:page, :key => "static/page1", :locale => I18n.locale) 70 | @static_page_1_body_content = create(:page_content, :page => @static_page_1_page, :key => "body") 71 | 72 | @static_page_2_page = create(:page, :key => "static/page2", :locale => I18n.locale) 73 | @static_page_2_body_content = create(:page_content, :page => @static_page_2_page, :key => "body") 74 | 75 | # Blog::HomeController 76 | @blogs_home_controller = Blog::HomeController.new 77 | @blog_page = create(:page, :key => @blogs_home_controller.controller_path, :locale => I18n.locale) 78 | end 79 | 80 | context "manageable_content_for helper" do 81 | context "with application layout" do 82 | context "HomeController" do 83 | it "should retrieve the correct content for :body" do 84 | @home_controller.manageable_content_for(:body).should == @home_body_content.content 85 | end 86 | it "should retrieve the correct content for :side" do 87 | @home_controller.manageable_content_for(:side).should == @home_side_content.content 88 | end 89 | it "should retrieve the correct content for :footer_copyright" do 90 | @home_controller.manageable_layout_content_for(:footer_copyright).should == 91 | @application_layout_footer_copyright_content.content 92 | end 93 | it "should retrieve the correct content for :footer_contact" do 94 | @home_controller.manageable_layout_content_for(:footer_contact).should == 95 | @application_layout_footer_contact_content.content 96 | end 97 | end 98 | 99 | context "ContactController" do 100 | it "should retrieve the correct content for :body" do 101 | @contact_controller.manageable_content_for(:body).should == 102 | @contact_body_content.content 103 | end 104 | it "should retrieve the correct content for :message" do 105 | @contact_controller.manageable_content_for(:message).should == 106 | @contact_message_content.content 107 | end 108 | it "should retrieve the correct content for :footer_copyright" do 109 | @contact_controller.manageable_layout_content_for(:footer_copyright).should == 110 | @application_layout_footer_copyright_content.content 111 | end 112 | it "should retrieve the correct content for :footer_contact" do 113 | @contact_controller.manageable_layout_content_for(:footer_contact).should == 114 | @application_layout_footer_contact_content.content 115 | end 116 | end 117 | end 118 | 119 | context "StaticPagesController" do 120 | it "should retrieve the correct content for static/page1 :body" do 121 | @static_pages_controller.stub(:params => {:page => "static/page1"}) 122 | @static_pages_controller.manageable_content_for(:body).should == 123 | @static_page_1_body_content.content 124 | end 125 | 126 | it "should retrieve the correct content for static/page2 :body" do 127 | @static_pages_controller.stub(:params => {:page => "static/page2"}) 128 | @static_pages_controller.manageable_content_for(:body).should == 129 | @static_page_2_body_content.content 130 | end 131 | end 132 | 133 | context "with blog layout" do 134 | context "Blog::HomeController" do 135 | it "should retrieve the correct content for :blog_title" do 136 | @blogs_home_controller.manageable_layout_content_for(:blog_title).should == 137 | @blog_layout_title_content.content 138 | end 139 | 140 | it "should retrieve nil for a non existent layout content" do 141 | @blogs_home_controller.manageable_layout_content_for(:non_existent).should be_nil 142 | end 143 | 144 | it "should retrieve nil for a non existent page content" do 145 | @blogs_home_controller.manageable_content_for(:non_existent).should be_nil 146 | end 147 | end 148 | end 149 | end 150 | end 151 | end 152 | end -------------------------------------------------------------------------------- /spec/lib/manageable_content/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ManageableContent::Manager do 4 | 5 | context "class methods" do 6 | 7 | context "eligible_controllers" do 8 | it "should list the eligible controllers" do 9 | ManageableContent::Manager.eligible_controllers.should == 10 | [ApplicationController, ContactController, HomeController] 11 | end 12 | end 13 | 14 | context "eligible_custom" do 15 | it "should list the eligible custom pages" do 16 | ManageableContent::Manager.eligible_custom.should == 17 | ["static/page1", "static/page2"] 18 | end 19 | end 20 | 21 | context "generate!" do 22 | before :each do 23 | ManageableContent::Manager.generate! 24 | end 25 | 26 | context "generated pages" do 27 | context "Layout" do 28 | context "application" do 29 | it "should have generated contents for each configured locale" do 30 | ManageableContent::Engine.config.locales.each do |locale| 31 | page = ManageableContent::Manager.page('application', locale).first 32 | 33 | page.key.should == 'application' 34 | page.locale.should == locale.to_s 35 | page.page_contents.size.should == 4 36 | page.page_content(:title).short.should be_true 37 | page.page_content(:keywords).short.should be_false 38 | page.page_content(:footer_copyright).short.should be_false 39 | page.page_content(:footer_contact).short.should be_true 40 | end 41 | end 42 | end 43 | 44 | context "blog" do 45 | it "should have generated contents for each configured locale" do 46 | ManageableContent::Engine.config.locales.each do |locale| 47 | page = ManageableContent::Manager.page('blog', locale).first 48 | 49 | page.key.should == 'blog' 50 | page.locale.should == locale.to_s 51 | page.page_contents.size.should == 1 52 | page.page_content(:blog_title).short.should be_false 53 | end 54 | end 55 | end 56 | end 57 | 58 | context "HomeController" do 59 | it "should have generated contents for each configured locale" do 60 | controller_path = HomeController.controller_path 61 | 62 | ManageableContent::Engine.config.locales.each do |locale| 63 | page = ManageableContent::Manager.page(controller_path, locale).first 64 | 65 | page.key.should == controller_path 66 | page.locale.should == locale.to_s 67 | page.page_contents.size.should == 4 68 | page.page_content(:title).short.should be_true 69 | page.page_content(:keywords).short.should be_false 70 | page.page_content(:body).short.should be_false 71 | page.page_content(:side).short.should be_false 72 | end 73 | end 74 | end 75 | 76 | context "ContactController" do 77 | it "should have generated contents for each configured locale" do 78 | controller_path = ContactController.controller_path 79 | 80 | ManageableContent::Engine.config.locales.each do |locale| 81 | page = ManageableContent::Manager.page(controller_path, locale).first 82 | 83 | page.key.should == controller_path 84 | page.locale.should == locale.to_s 85 | page.page_contents.size.should == 4 86 | page.page_content(:title).short.should be_true 87 | page.page_content(:keywords).short.should be_false 88 | page.page_content(:body).short.should be_false 89 | page.page_content(:message).short.should be_false 90 | end 91 | end 92 | end 93 | 94 | context "Custom Pages" do 95 | it "should have generated contents for each configured locale" do 96 | controller_path = ContactController.controller_path 97 | 98 | ManageableContent::Engine.config.locales.each do |locale| 99 | # Page1 100 | page = ManageableContent::Manager.page("static/page1", locale).first 101 | page.key.should == "static/page1" 102 | page.locale.should == locale.to_s 103 | page.page_contents.size.should == 1 104 | page.page_content(:body).short.should be_false 105 | 106 | # Page1=2 107 | page = ManageableContent::Manager.page("static/page2", locale).first 108 | page.key.should == "static/page2" 109 | page.locale.should == locale.to_s 110 | page.page_contents.size.should == 2 111 | page.page_content(:body).short.should be_false 112 | page.page_content(:footer).short.should be_true 113 | end 114 | end 115 | end 116 | 117 | context "Blog::HomeController" do 118 | it "should NOT have generated contents for each configured locale" do 119 | controller_path = Blog::HomeController.controller_path 120 | 121 | ManageableContent::Engine.config.locales.each do |locale| 122 | ManageableContent::Manager.page(controller_path, locale).first.should be_nil 123 | end 124 | end 125 | end 126 | end 127 | 128 | context "pages" do 129 | before :each do 130 | #adding a mock page that should be non eligible 131 | create :page 132 | end 133 | 134 | it "should list the eligible pages" do 135 | ManageableContent::Manager.pages.should == 136 | ([ApplicationController, ContactController, HomeController].map do |controller_class| 137 | ManageableContent::Engine.config.locales.map do |locale| 138 | ManageableContent::Manager.page(controller_class.controller_path, locale).first 139 | end 140 | end.flatten + ["static/page1", "static/page2"].map do |custom_page_key| 141 | ManageableContent::Engine.config.locales.map do |locale| 142 | ManageableContent::Manager.page(custom_page_key, locale).first 143 | end 144 | end.flatten) 145 | end 146 | 147 | it "should list the eligible contents" do 148 | ManageableContent::Manager.eligible_contents(HomeController.controller_path).should == 149 | {:title => :string, :keywords => :text, :body => :text, :side => :text} 150 | 151 | ManageableContent::Manager.eligible_contents("static/page1").should == 152 | {:body => :text} 153 | 154 | ManageableContent::Manager.eligible_contents("static/page2").should == 155 | {:body => :text, :footer => :string} 156 | end 157 | end 158 | 159 | context "page" do 160 | it "should retrieve pages correctly" do 161 | [ApplicationController, ContactController, HomeController].each do |controller_class| 162 | ManageableContent::Engine.config.locales.each do |locale| 163 | page = ManageableContent::Manager.page(controller_class.controller_path, locale).first 164 | 165 | page.key.should == controller_class.controller_path 166 | page.locale.should == locale.to_s 167 | end 168 | end 169 | end 170 | end 171 | end 172 | end 173 | end --------------------------------------------------------------------------------