chosen_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bd2af944e89c815d3deb3b3f222c7cc804e390d
4
+ data.tar.gz: 6cc2961f080696772814efdcff3d4b33b5a61cf9
5
+ SHA512:
6
+ metadata.gz: 7de56b38e4ba3053e6362507b168249b234b930931c46a0530911df2f7cfdd9fc873edbd5765a456198bb6fadbd6465bfbdd7845426e37db825ee5811582766f
7
+ data.tar.gz: ba1de32277dbff9fad3a34200cce1b2b1540ea079cbd8a7094587f3db8fe922568293c9ee60f0527af9f6fb6370f5c6b8fa97c485f91742abbf6fd3b90fd6707
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ db/*.sqlite3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chosen_template.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'database_cleaner'
8
+ gem 'timecop'
9
+ gem 'pry'
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ramon Tayag
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # ChosenTemplate
2
+
3
+ Helper methods that allow users of an app to choose a template for one of the records, and previewing it before hand. Difficult to explain, but here's a scenario:
4
+
5
+ You have a CMS. Each page's layout can be changed by the owner of the site. The layout that was "published" by the user can be used to show to the public. However, before the layout is published, the user wants to preview the page in that new layout. To do this, the user "previews" it. This can be typically shown in another route namespace that only site owners have access.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'chosen_template'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chosen_template
20
+
21
+ ## Usage
22
+
23
+ The item that can be preview and published:
24
+
25
+ class PageTemplate < ActiveRecord::Base
26
+ belongs_to :page
27
+ choosable_template by: :page
28
+ end
29
+
30
+ The model that does the choosing:
31
+
32
+ class Page < ActiveRecord::Base
33
+ has_many :page_templates
34
+ chooses_templates :page_templates
35
+ end
36
+
37
+ Here is how you would use it:
38
+
39
+ Get the page template that was chosen as the preview template:
40
+
41
+ page.previewed_page_template
42
+
43
+ Get the page template that was chosen as the published template:
44
+
45
+ page.published_page_template
46
+
47
+ Want to know if a specific page template is published template of the previewed template?
48
+
49
+ page_template.previewed_template?
50
+ page_template.published_template?
51
+
52
+ When you want to mark a page template as previewed:
53
+
54
+ page_template.preview_template! # simply updates the page_template's template_previewed_at to be right now
55
+
56
+ When you want to mark a page template as published:
57
+
58
+ page_template.publish_template! # simply updates the page_template's template_published_at to be right now
59
+
60
+ Other useful scopes that can be called on the collection of templates:
61
+
62
+ - `published_templates` returns templates that were ever published
63
+ - `previewed_templates` returns templates that were ever previewed
64
+ - `by_template_published_at` returns templates ordered by the date they were published, from most newest to oldest
65
+ - `by_template_previewed_at` returns templates ordered by the date they were previewed, from most newest to oldest
66
+
67
+ ## Running Specs
68
+
69
+ In the root folder:
70
+
71
+ bundle install
72
+ rake db:migrate DB=test
73
+ rspec spec
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'standalone_migrations'
3
+ StandaloneMigrations::Tasks.load_tasks
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chosen_template/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chosen_template"
8
+ spec.version = ChosenTemplate::VERSION
9
+ spec.authors = ["Ramon Tayag"]
10
+ spec.email = ["ramon.tayag@gmail.com"]
11
+ spec.description = %q{Manage the preview and publish tasks of templates}
12
+ spec.summary = %q{Manage the preview and publish tasks of templates. See the readme for a scenario as I don't know how else to describe it!}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 2.13.0"
24
+ spec.add_development_dependency "factory_girl", "~> 4.2.0"
25
+ spec.add_development_dependency 'sqlite3'
26
+ spec.add_development_dependency 'standalone_migrations', '~> 2.1.1'
27
+ spec.add_dependency "activerecord", ">= 3.0.0"
28
+ spec.add_dependency "activesupport", ">= 3.0.0"
29
+ end
data/db/config.yml ADDED
@@ -0,0 +1,11 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test: &test
8
+ adapter: sqlite3
9
+ database: db/test.sqlite3
10
+ pool: 5
11
+ timeout: 5000
@@ -0,0 +1,12 @@
1
+ class CreatePages < ActiveRecord::Migration
2
+ def up
3
+ create_table :pages do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :pages
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePageTemplates < ActiveRecord::Migration
2
+ def up
3
+ create_table :page_templates do |t|
4
+ t.string :name
5
+ t.references :page
6
+ t.datetime :template_published_at
7
+ t.datetime :template_previewed_at
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def down
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreateStyles < ActiveRecord::Migration
2
+ def up
3
+ create_table :styles do |t|
4
+ t.string :name
5
+ t.references :page
6
+ t.datetime :template_published_at
7
+ t.datetime :template_previewed_at
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :styles
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateBodyStyles < ActiveRecord::Migration
2
+ def up
3
+ create_table :body_styles do |t|
4
+ t.string :name
5
+ t.datetime :template_published_at
6
+ t.datetime :template_previewed_at
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def down
12
+ drop_table :body_styles
13
+ end
14
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,48 @@
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 => 20130526033402) do
15
+
16
+ create_table "body_styles", :force => true do |t|
17
+ t.string "name"
18
+ t.datetime "template_published_at"
19
+ t.datetime "template_previewed_at"
20
+ t.datetime "created_at", :null => false
21
+ t.datetime "updated_at", :null => false
22
+ end
23
+
24
+ create_table "page_templates", :force => true do |t|
25
+ t.string "name"
26
+ t.integer "page_id"
27
+ t.datetime "template_published_at"
28
+ t.datetime "template_previewed_at"
29
+ t.datetime "created_at", :null => false
30
+ t.datetime "updated_at", :null => false
31
+ end
32
+
33
+ create_table "pages", :force => true do |t|
34
+ t.string "name"
35
+ t.datetime "created_at", :null => false
36
+ t.datetime "updated_at", :null => false
37
+ end
38
+
39
+ create_table "styles", :force => true do |t|
40
+ t.string "name"
41
+ t.integer "page_id"
42
+ t.datetime "template_published_at"
43
+ t.datetime "template_previewed_at"
44
+ t.datetime "created_at", :null => false
45
+ t.datetime "updated_at", :null => false
46
+ end
47
+
48
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/class'
3
+ require 'active_support/inflector'
4
+ require "chosen_template/version"
5
+ require 'chosen_template/chooser'
6
+ require 'chosen_template/chosen'
7
+
8
+ module ChosenTemplate
9
+ CHOOSABLE_REQUIRED_COLUMNS = [:template_published_at, :template_previewed_at]
10
+
11
+ extend ActiveSupport::Concern
12
+
13
+ module ClassMethods
14
+ def chooses_templates(*template_choices)
15
+ cattr_accessor :template_choices
16
+ self.template_choices = template_choices
17
+ include Chooser
18
+ end
19
+
20
+ def choosable_template(options={})
21
+ cattr_accessor :chosen_by
22
+ self.chosen_by = options[:by]
23
+
24
+ CHOOSABLE_REQUIRED_COLUMNS.each do |column_name|
25
+ unless self.column_names.include?(column_name.to_s)
26
+ raise ArgumentError, "`#{self.table_name}` requires the `#{column_name}` column"
27
+ end
28
+ end
29
+ include Chosen
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ ActiveRecord::Base.send :include, ChosenTemplate
@@ -0,0 +1,28 @@
1
+ module ChosenTemplate
2
+ module Chooser
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ self.template_choices.each do |template_choice|
9
+ [:previewed, :published].each do |action_type|
10
+ method_name = :"#{action_type}_#{template_choice.to_s.singularize}"
11
+ define_method(method_name) do
12
+ order_scope_name = :"by_template_#{action_type}_at"
13
+ template_class = template_choice.to_s.classify.constantize
14
+ foreign_key = "#{self.class.name.underscore}_id"
15
+ template_scope = if template_class.column_names.include?(foreign_key)
16
+ self.send(template_choice)
17
+ else
18
+ template_class.scoped
19
+ end
20
+ template_scope.send(order_scope_name).first
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ module ChosenTemplate
2
+ module Chosen
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ scope :published_templates, -> {
8
+ where("#{self.table_name}.template_published_at IS NOT NULL")
9
+ }
10
+ scope :by_template_published_at, -> {
11
+ published_templates.order("#{self.table_name}.template_published_at DESC")
12
+ }
13
+ scope :previewed_templates, -> {
14
+ where("#{self.table_name}.template_previewed_at IS NOT NULL")
15
+ }
16
+ scope :by_template_previewed_at, -> {
17
+ previewed_templates.order("#{self.table_name}.template_previewed_at DESC")
18
+ }
19
+ end
20
+
21
+ def previewed_template?
22
+ self.class.by_template_previewed_at.first == self
23
+ end
24
+
25
+ def preview_template!
26
+ self.update_attributes template_previewed_at: Time.now
27
+ end
28
+
29
+ def published_template?
30
+ self.class.by_template_published_at.first == self
31
+ end
32
+
33
+ def publish_template!
34
+ self.update_attributes template_published_at: Time.now
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module ChosenTemplate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChosenTemplate do
4
+ it 'should allow the chooser to preview', integration: true do
5
+ end
6
+
7
+ it 'should allow the chooser to publish', integration: true do
8
+ end
9
+
10
+ describe '.choosable_template' do
11
+ context 'when the model does not have the template_previewed_at field' do
12
+ it 'should raise an exception' do
13
+ expect { Page.choosable_template }.to raise_error(ArgumentError)
14
+ end
15
+ end
16
+
17
+ context 'when the model does not have the template_published_at field' do
18
+ it 'should raise an exception' do
19
+ expect { Page.choosable_template }.to raise_error(ArgumentError)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :page do
4
+ end
5
+
6
+ factory :page_template do
7
+ end
8
+
9
+ factory :body_style do
10
+ end
11
+
12
+ factory :style do
13
+ end
14
+
15
+ end
data/spec/page_spec.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Page do
4
+ let(:page) { build_stubbed(:page) }
5
+
6
+ describe '#previewed_page_template' do
7
+ it 'should return the chosen previewed page template' do
8
+ page_template = build_stubbed(:page_template)
9
+ page.stub_chain(:page_templates, :by_template_previewed_at, :first) {
10
+ page_template
11
+ }
12
+ page.previewed_page_template.should == page_template
13
+ end
14
+ end
15
+
16
+ describe '#published_page_template' do
17
+ it 'should return the chosen published page template' do
18
+ page_template = build_stubbed(:page_template)
19
+ page.stub_chain(:page_templates, :by_template_published_at, :first) {
20
+ page_template
21
+ }
22
+ page.published_page_template.should == page_template
23
+ end
24
+ end
25
+
26
+ describe '#previewed_style' do
27
+ it 'should return the chosen previewed page template' do
28
+ style = build_stubbed(:style)
29
+ page.stub_chain(:styles, :by_template_previewed_at, :first) {
30
+ style
31
+ }
32
+ page.previewed_style.should == style
33
+ end
34
+ end
35
+
36
+ describe '#published_style' do
37
+ it 'should return the chosen style' do
38
+ style = build_stubbed(:style)
39
+ page.stub_chain(:styles, :by_template_published_at, :first) {
40
+ style
41
+ }
42
+ page.published_style.should == style
43
+ end
44
+ end
45
+
46
+ context 'when the template does not have a reference to the page' do
47
+ # NOTE: One of the reasons this is useful: if you have a multitenant app,
48
+ # split up by Site each having their own database or namespace. If there is
49
+ # a SiteLayout model, but that model does not have a site_id (why should it
50
+ # - Site lives on the public namespace).
51
+ describe '#previewed_body_style' do
52
+ it 'should go directly through BodyStyle class' do
53
+ body_style = build_stubbed(:body_style)
54
+ BodyStyle.stub_chain(:by_template_previewed_at, :first) { body_style }
55
+ page.previewed_body_style.should == body_style
56
+ end
57
+ end
58
+
59
+ describe '#published_body_style' do
60
+ it 'should go directly through BodyStyle class' do
61
+ body_style = build_stubbed(:body_style)
62
+ BodyStyle.stub_chain(:by_template_published_at, :first) { body_style }
63
+ page.published_body_style.should == body_style
64
+ end
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe PageTemplate do
4
+
5
+ describe '.published_templates' do
6
+ it 'should return the published models' do
7
+ described_class.published_templates.to_sql.should ==
8
+ %Q(SELECT "#{described_class.table_name}".* FROM "#{described_class.table_name}" WHERE (#{described_class.table_name}.template_published_at IS NOT NULL))
9
+ end
10
+ end
11
+
12
+ describe '.by_template_published_at' do
13
+ it 'should order the published models by template_published_at' do
14
+ described_class.by_template_published_at.to_sql.should ==
15
+ %Q(SELECT "#{described_class.table_name}".* FROM "#{described_class.table_name}" WHERE (#{described_class.table_name}.template_published_at IS NOT NULL) ORDER BY #{described_class.table_name}.template_published_at DESC)
16
+ end
17
+ end
18
+
19
+ describe '.previewed_templates' do
20
+ it 'should return the preview models' do
21
+ described_class.previewed_templates.to_sql.should ==
22
+ %Q(SELECT "#{described_class.table_name}".* FROM "#{described_class.table_name}" WHERE (#{described_class.table_name}.template_previewed_at IS NOT NULL))
23
+ end
24
+ end
25
+
26
+ describe '.by_template_previewed_at' do
27
+ it 'should order the previewed models by template_previewed_at' do
28
+ described_class.by_template_previewed_at.to_sql.should ==
29
+ %Q(SELECT "#{described_class.table_name}".* FROM "#{described_class.table_name}" WHERE (#{described_class.table_name}.template_previewed_at IS NOT NULL) ORDER BY #{described_class.table_name}.template_previewed_at DESC)
30
+ end
31
+ end
32
+
33
+ describe '#previewed_template?' do
34
+ context 'page is the latest marked as previewed' do
35
+ it 'should be true' do
36
+ style = build_stubbed(:page_template)
37
+ another_style = build_stubbed(:page_template)
38
+ described_class.stub(:by_template_previewed_at) { [style, another_style] }
39
+ style.should be_previewed_template
40
+ end
41
+ end
42
+
43
+ context 'style is not the latest previewed' do
44
+ it 'should be true' do
45
+ another_style = build_stubbed(:page_template)
46
+ style = build_stubbed(:page_template)
47
+ described_class.stub(:by_template_previewed_at) { [another_style, style] }
48
+ style.should_not be_previewed_template
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#preview_template!' do
54
+ it 'should update the template_previewed_at column' do
55
+ Timecop.freeze 2.minutes.ago
56
+ style = build_stubbed(:page_template)
57
+ style.should_receive(:update_attributes).
58
+ with(template_previewed_at: Time.now)
59
+ style.preview_template!
60
+ end
61
+ end
62
+
63
+ describe '#published_template?' do
64
+ context 'style is the latest marked as published' do
65
+ it 'should be true' do
66
+ style = build_stubbed(:page_template)
67
+ another_style = build_stubbed(:page_template)
68
+ described_class.stub(:by_template_published_at) { [style, another_style] }
69
+ style.should be_published_template
70
+ end
71
+ end
72
+
73
+ context 'style is not the latest published' do
74
+ it 'should be true' do
75
+ another_style = build_stubbed(:page_template)
76
+ style = build_stubbed(:page_template)
77
+ described_class.stub(:by_template_published_at) { [another_style, style] }
78
+ style.should_not be_published_template
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#publish_template!' do
84
+ it 'should update the previewed_at column' do
85
+ Timecop.freeze 2.minutes.ago
86
+ style = build_stubbed(:page_template)
87
+ style.should_receive(:update_attributes).
88
+ with(template_published_at: Time.now)
89
+ style.publish_template!
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,33 @@
1
+ require 'rspec'
2
+ require 'bundler/setup'
3
+ require 'active_record'
4
+ require 'chosen_template'
5
+
6
+ ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
7
+ SPEC_DIR = File.expand_path(File.dirname(__FILE__))
8
+
9
+ Bundler.require(:test)
10
+
11
+ Dir[File.join(SPEC_DIR, 'support', "**/*.rb")].each do |f|
12
+ require f
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ config.order = 'random'
18
+
19
+ config.before :suite do
20
+ DatabaseCleaner.clean_with :truncation
21
+ end
22
+
23
+ config.before :each do
24
+ DatabaseCleaner.strategy = :transaction
25
+ DatabaseCleaner.start
26
+ Timecop.return
27
+ end
28
+
29
+ config.after do
30
+ DatabaseCleaner.clean
31
+ end
32
+
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+
3
+ database_yml = File.join(ROOT_DIR, 'db', 'config.yml')
4
+ db_config = YAML.load_file(database_yml).with_indifferent_access
5
+ ActiveRecord::Base.establish_connection(db_config[:test])
@@ -0,0 +1,8 @@
1
+ require 'factory_girl'
2
+ Dir.glob(File.join(SPEC_DIR, 'factories', '**', '*.rb')).each do |f|
3
+ require f
4
+ end
5
+
6
+ RSpec.configure do |config|
7
+ config.include FactoryGirl::Syntax::Methods
8
+ end
@@ -0,0 +1,3 @@
1
+ Dir.glob(File.join(SPEC_DIR, 'models', '**', '*.rb')).each do |f|
2
+ require f
3
+ end
@@ -0,0 +1,3 @@
1
+ class BodyStyle < ActiveRecord::Base
2
+ choosable_template by: :page
3
+ end
@@ -0,0 +1,3 @@
1
+ class Page < ActiveRecord::Base
2
+ chooses_templates :page_templates, :styles, :body_styles
3
+ end
@@ -0,0 +1,4 @@
1
+ class PageTemplate < ActiveRecord::Base
2
+ belongs_to :page
3
+ choosable_template by: :page
4
+ end
@@ -0,0 +1,4 @@
1
+ class Style < ActiveRecord::Base
2
+ belongs_to :page
3
+ choosable_template by: :page
4
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chosen_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ramon Tayag
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.13.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.13.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: standalone_migrations
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.0
125
+ description: Manage the preview and publish tasks of templates
126
+ email:
127
+ - ramon.tayag@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - chosen_template.gemspec
138
+ - db/config.yml
139
+ - db/migrate/20130526013748_create_pages.rb
140
+ - db/migrate/20130526014011_create_page_templates.rb
141
+ - db/migrate/20130526024132_create_styles.rb
142
+ - db/migrate/20130526033402_create_body_styles.rb
143
+ - db/schema.rb
144
+ - lib/chosen_template.rb
145
+ - lib/chosen_template/chooser.rb
146
+ - lib/chosen_template/chosen.rb
147
+ - lib/chosen_template/version.rb
148
+ - spec/chosen_template_spec.rb
149
+ - spec/factories/all.rb
150
+ - spec/page_spec.rb
151
+ - spec/page_template_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support/active_record.rb
154
+ - spec/support/factory_girl.rb
155
+ - spec/support/loader.rb
156
+ - spec/support/models/body_styles.rb
157
+ - spec/support/models/page.rb
158
+ - spec/support/models/page_template.rb
159
+ - spec/support/models/style.rb
160
+ homepage: ''
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.0.3
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Manage the preview and publish tasks of templates. See the readme for a scenario
184
+ as I don't know how else to describe it!
185
+ test_files:
186
+ - spec/chosen_template_spec.rb
187
+ - spec/factories/all.rb
188
+ - spec/page_spec.rb
189
+ - spec/page_template_spec.rb
190
+ - spec/spec_helper.rb
191
+ - spec/support/active_record.rb
192
+ - spec/support/factory_girl.rb
193
+ - spec/support/loader.rb
194
+ - spec/support/models/body_styles.rb
195
+ - spec/support/models/page.rb
196
+ - spec/support/models/page_template.rb
197
+ - spec/support/models/style.rb