From 7c59cfe534e40be717636e99dec6dad7fa958e6f Mon Sep 17 00:00:00 2001 From: Paul Engel Date: Tue, 9 Nov 2010 02:01:21 +0100 Subject: [PATCH] Generated enrichments --- app/models/cms_content.rb | 2 ++ app/models/translation.rb | 7 ++++++ app/models/user.rb | 8 ++++++ app/models/user_session.rb | 11 ++++++++ config/initializers/enrichments.rb | 4 +++ db/migrate/20101109015924_create_users.rb | 25 +++++++++++++++++++ .../20101109015929_create_cms_contents.rb | 15 +++++++++++ .../20101109015932_create_translations.rb | 18 +++++++++++++ test/fixtures/cms_contents.yml | 11 ++++++++ test/unit/cms_content_test.rb | 8 ++++++ 10 files changed, 109 insertions(+) create mode 100644 app/models/cms_content.rb create mode 100644 app/models/translation.rb create mode 100644 app/models/user.rb create mode 100644 app/models/user_session.rb create mode 100644 config/initializers/enrichments.rb create mode 100644 db/migrate/20101109015924_create_users.rb create mode 100644 db/migrate/20101109015929_create_cms_contents.rb create mode 100644 db/migrate/20101109015932_create_translations.rb create mode 100644 test/fixtures/cms_contents.yml create mode 100644 test/unit/cms_content_test.rb diff --git a/app/models/cms_content.rb b/app/models/cms_content.rb new file mode 100644 index 0000000..de8bf1c --- /dev/null +++ b/app/models/cms_content.rb @@ -0,0 +1,2 @@ +class CmsContent < ActiveRecord::Base +end diff --git a/app/models/translation.rb b/app/models/translation.rb new file mode 100644 index 0000000..46d886b --- /dev/null +++ b/app/models/translation.rb @@ -0,0 +1,7 @@ +class Translation < ActiveRecord::Base + + def to_rich_cms_response(params) + {:value => value, :translations => Hash[*params[:derivative_keys].split(";").uniq.collect{|x| [x, x.t({:as => params[:editable_input_type]})]}.flatten]} + end + +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..8a07b5d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,8 @@ +class User < ActiveRecord::Base + + acts_as_authentic do |c| + c.login_field = :email + c.crypted_password_field = :crypted_password + end + +end \ No newline at end of file diff --git a/app/models/user_session.rb b/app/models/user_session.rb new file mode 100644 index 0000000..9b926ae --- /dev/null +++ b/app/models/user_session.rb @@ -0,0 +1,11 @@ +class UserSession < Authlogic::Session::Base + + authenticate_with User + generalize_credentials_error_messages true + params_key "user_credentials" + + def to_key + new_record? ? nil : [self.send self.class.primary_key] + end + +end \ No newline at end of file diff --git a/config/initializers/enrichments.rb b/config/initializers/enrichments.rb new file mode 100644 index 0000000..e6e0ca0 --- /dev/null +++ b/config/initializers/enrichments.rb @@ -0,0 +1,4 @@ + +Rich::Cms::Engine.authenticate(:authlogic, {:class_name => "User", :identifier => :email}) +Rich::Cms::Engine.register(".cms_content", {:class_name => "CmsContent"}) +Rich::I18n::Engine.enable_i18n_cms \ No newline at end of file diff --git a/db/migrate/20101109015924_create_users.rb b/db/migrate/20101109015924_create_users.rb new file mode 100644 index 0000000..814201c --- /dev/null +++ b/db/migrate/20101109015924_create_users.rb @@ -0,0 +1,25 @@ +class CreateUsers < ActiveRecord::Migration + def self.up + create_table :users do |t| + t.string :name + t.string :email + t.string :crypted_password + t.string :password_salt + t.datetime :created_at + t.string :persistence_token , :default => "", :null => false + t.string :single_access_token, :default => "", :null => false + t.string :perishable_token , :default => "", :null => false + t.integer :login_count + t.datetime :last_request_at + t.datetime :current_login_at + t.datetime :last_login_at + t.timestamps + end + + add_index :users, :email + end + + def self.down + drop_table :users + end +end \ No newline at end of file diff --git a/db/migrate/20101109015929_create_cms_contents.rb b/db/migrate/20101109015929_create_cms_contents.rb new file mode 100644 index 0000000..6afc88c --- /dev/null +++ b/db/migrate/20101109015929_create_cms_contents.rb @@ -0,0 +1,15 @@ +class CreateCmsContents < ActiveRecord::Migration + def self.up + create_table :cms_contents do |t| + t.string :key + t.text :value + t.timestamps + end + + add_index :cms_contents, :key + end + + def self.down + drop_table :cms_contents + end +end \ No newline at end of file diff --git a/db/migrate/20101109015932_create_translations.rb b/db/migrate/20101109015932_create_translations.rb new file mode 100644 index 0000000..260fb0b --- /dev/null +++ b/db/migrate/20101109015932_create_translations.rb @@ -0,0 +1,18 @@ +class CreateTranslations < ActiveRecord::Migration + def self.up + create_table :translations do |t| + t.string :locale + t.string :key + t.text :value + t.boolean :is_proc, :default => false + t.timestamps + end + + add_index :translations, :locale + add_index :translations, :key + end + + def self.down + drop_table :translations + end +end \ No newline at end of file diff --git a/test/fixtures/cms_contents.yml b/test/fixtures/cms_contents.yml new file mode 100644 index 0000000..2893341 --- /dev/null +++ b/test/fixtures/cms_contents.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/unit/cms_content_test.rb b/test/unit/cms_content_test.rb new file mode 100644 index 0000000..946faf8 --- /dev/null +++ b/test/unit/cms_content_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class CmsContentTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end