push_type_core 0.1.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +22 -0
  3. data/README.md +3 -0
  4. data/app/controllers/push_type/application_controller.rb +4 -0
  5. data/app/controllers/push_type/front_end_controller.rb +21 -0
  6. data/app/fields/push_type/date_field.rb +11 -0
  7. data/app/fields/push_type/number_field.rb +15 -0
  8. data/app/fields/push_type/rich_text_field.rb +10 -0
  9. data/app/fields/push_type/string_field.rb +4 -0
  10. data/app/fields/push_type/text_field.rb +7 -0
  11. data/app/helpers/push_type/application_helper.rb +4 -0
  12. data/app/models/concerns/push_type/field_store.rb +56 -0
  13. data/app/models/concerns/push_type/nestable.rb +23 -0
  14. data/app/models/concerns/push_type/templatable.rb +33 -0
  15. data/app/models/concerns/push_type/trashable.rb +23 -0
  16. data/app/models/push_type/asset.rb +61 -0
  17. data/app/models/push_type/node.rb +57 -0
  18. data/app/models/push_type/user.rb +18 -0
  19. data/app/views/layouts/push_type/application.html.erb +14 -0
  20. data/config/initializers/dragonfly.rb +24 -0
  21. data/config/routes.rb +2 -0
  22. data/db/migrate/20141117170533_create_push_type_users.rb +12 -0
  23. data/db/migrate/20141117204630_create_push_type_nodes.rb +24 -0
  24. data/db/migrate/20141117210644_create_push_type_node_hierarchies.rb +16 -0
  25. data/db/migrate/20141127151930_create_push_type_assets.rb +18 -0
  26. data/lib/generators/push_type/dummy/dummy_generator.rb +56 -0
  27. data/lib/generators/push_type/dummy/templates/application.rb +14 -0
  28. data/lib/generators/push_type/dummy/templates/boot.rb +4 -0
  29. data/lib/generators/push_type/dummy/templates/page.rb +6 -0
  30. data/lib/generators/push_type/install/install_generator.rb +28 -0
  31. data/lib/generators/push_type/install/templates/push_type.rb +5 -0
  32. data/lib/generators/push_type/node/USAGE +8 -0
  33. data/lib/generators/push_type/node/node_generator.rb +12 -0
  34. data/lib/generators/push_type/node/templates/node.rb +10 -0
  35. data/lib/generators/push_type/node/templates/template.html.erb +3 -0
  36. data/lib/push_type/core/engine.rb +24 -0
  37. data/lib/push_type/core.rb +45 -0
  38. data/lib/push_type/field_type.rb +40 -0
  39. data/lib/push_type/rails/routes.rb +19 -0
  40. data/lib/push_type/testing/common_rake.rb +19 -0
  41. data/lib/push_type/testing/factories.rb +41 -0
  42. data/lib/push_type/testing/setup.rb +26 -0
  43. data/lib/push_type/testing/support/expectations.rb +10 -0
  44. data/lib/push_type_core.rb +1 -0
  45. data/lib/tasks/push_type_tasks.rake +4 -0
  46. data/test/controllers/push_type/front_end_controller_test.rb +31 -0
  47. data/test/dummy/README.rdoc +28 -0
  48. data/test/dummy/Rakefile +6 -0
  49. data/test/dummy/app/assets/javascripts/application.js +16 -0
  50. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  51. data/test/dummy/app/controllers/application_controller.rb +5 -0
  52. data/test/dummy/app/helpers/application_helper.rb +2 -0
  53. data/test/dummy/app/models/page.rb +10 -0
  54. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  55. data/test/dummy/app/views/nodes/page.html.erb +3 -0
  56. data/test/dummy/bin/bundle +3 -0
  57. data/test/dummy/bin/rails +4 -0
  58. data/test/dummy/bin/rake +4 -0
  59. data/test/dummy/config/application.rb +14 -0
  60. data/test/dummy/config/boot.rb +4 -0
  61. data/test/dummy/config/database.yml +85 -0
  62. data/test/dummy/config/environment.rb +5 -0
  63. data/test/dummy/config/environments/development.rb +37 -0
  64. data/test/dummy/config/environments/production.rb +78 -0
  65. data/test/dummy/config/environments/test.rb +39 -0
  66. data/test/dummy/config/initializers/assets.rb +8 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  69. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/test/dummy/config/initializers/inflections.rb +16 -0
  71. data/test/dummy/config/initializers/mime_types.rb +4 -0
  72. data/test/dummy/config/initializers/push_type.rb +5 -0
  73. data/test/dummy/config/initializers/session_store.rb +3 -0
  74. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/test/dummy/config/locales/en.yml +23 -0
  76. data/test/dummy/config/routes.rb +59 -0
  77. data/test/dummy/config/secrets.yml +22 -0
  78. data/test/dummy/config.ru +4 -0
  79. data/test/dummy/db/migrate/20141205213452_create_push_type_users.push_type.rb +13 -0
  80. data/test/dummy/db/migrate/20141205213453_create_push_type_nodes.push_type.rb +25 -0
  81. data/test/dummy/db/migrate/20141205213454_create_push_type_node_hierarchies.push_type.rb +17 -0
  82. data/test/dummy/db/migrate/20141205213455_create_push_type_assets.push_type.rb +19 -0
  83. data/test/dummy/db/schema.rb +67 -0
  84. data/test/dummy/db/seeds.rb +7 -0
  85. data/test/dummy/log/test.log +1234 -0
  86. data/test/dummy/public/404.html +67 -0
  87. data/test/dummy/public/422.html +67 -0
  88. data/test/dummy/public/500.html +66 -0
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/dummy/public/robots.txt +5 -0
  91. data/test/files/audio.m3u +1 -0
  92. data/test/files/document.pdf +0 -0
  93. data/test/files/image.png +0 -0
  94. data/test/files/video.mp4 +0 -0
  95. data/test/models/push_type/asset_test.rb +63 -0
  96. data/test/models/push_type/node_test.rb +87 -0
  97. data/test/models/push_type/user_test.rb +24 -0
  98. data/test/test_helper.rb +19 -0
  99. metadata +293 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e5cfc57c3068c45c73376c6905e192f03321f06
4
+ data.tar.gz: 04013f98749da8c8a5be4902c7041fbae14c79d5
5
+ SHA512:
6
+ metadata.gz: 291069e98b7024375031e14c0abfd2aec2d01e904c2e24ac9fbb1a011b5f1ca91a04a917c8e85c567f5d267e88599ed3e8d69c08a5fe369903938b3198776ab5
7
+ data.tar.gz: 7eb951c044e25becd8ce2764713aec11e669b43d4cc5a9308adae8c8ee23063cf3585f7f5c617379878cbeb0eab108c42e75a16268341c26b46a64437ad45fdc
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ # PushType License
2
+
3
+ Copyright 2014 Push Code Ltd
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,3 @@
1
+ # PushType-Core
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,4 @@
1
+ module PushType
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,21 @@
1
+ require_dependency "push_type/application_controller"
2
+
3
+ module PushType
4
+ class FrontEndController < ApplicationController
5
+
6
+ before_filter :load_node, only: :node
7
+
8
+ def node
9
+ render *@node.template_args
10
+ end
11
+
12
+ private
13
+
14
+ def load_node
15
+ @node = PushType::Node.published.find_by_path params[:permalink].split('/')
16
+ raise ActiveRecord::RecordNotFound unless @node
17
+ instance_variable_set "@#{ @node.type.underscore }", @node
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module PushType
2
+ class DateField < PushType::FieldType
3
+ def form_helper
4
+ @opts[:form_helper] || :date_field
5
+ end
6
+
7
+ def from_json(val)
8
+ val.to_date
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module PushType
2
+ class NumberField < PushType::FieldType
3
+ def form_helper
4
+ @opts[:form_helper] || :number_field
5
+ end
6
+
7
+ def to_json(val)
8
+ val.to_i
9
+ end
10
+
11
+ def from_json(val)
12
+ val.to_i
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module PushType
2
+ class RichTextField < PushType::FieldType
3
+ def form_helper
4
+ :text_area
5
+ end
6
+ def html_options
7
+ super.merge(class: 'froala')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module PushType
2
+ class StringField < PushType::FieldType
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module PushType
2
+ class TextField < PushType::FieldType
3
+ def form_helper
4
+ @opts[:form_helper] || :text_area
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module PushType
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,56 @@
1
+ module PushType
2
+ module FieldStore
3
+ extend ActiveSupport::Concern
4
+
5
+ def fields
6
+ self.class.fields
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ attr_reader :fields
12
+
13
+ def fields
14
+ @fields ||= ActiveSupport::OrderedHash.new
15
+ end
16
+
17
+ def field(name, *args)
18
+ raise ArgumentError if args.size > 2
19
+ kind, opts = case args.size
20
+ when 2 then args
21
+ when 1 then args[0].is_a?(Hash) ? args.insert(0, :string) : args.insert(-1, {})
22
+ else [ :string, {} ]
23
+ end
24
+
25
+ fields[name] = field_factory(kind).new(name, opts)
26
+ store_accessor :field_store, name
27
+
28
+ validates name, opts[:validates] if opts[:validates]
29
+
30
+ override_accessor fields[name]
31
+ end
32
+
33
+ protected
34
+
35
+ def field_factory(kind)
36
+ begin
37
+ "push_type/#{ kind }_field".camelize.constantize
38
+ rescue NameError
39
+ "#{ kind }_field".camelize.constantize
40
+ end
41
+ end
42
+
43
+ def override_accessor(f)
44
+ define_method "#{f.name}=".to_sym do |val|
45
+ return unless val
46
+ super f.to_json(val)
47
+ end
48
+ define_method f.name do
49
+ return unless val = super()
50
+ f.from_json val
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ module PushType
2
+ module Nestable
3
+ extend ActiveSupport::Concern
4
+
5
+ def child_node_types
6
+ self.class.child_node_types
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def child_node_types
12
+ types = @child_node_types || PushType.config.root_node_types
13
+ PushType.node_types_from_list(types)
14
+ end
15
+
16
+ def has_child_nodes(*args)
17
+ @child_node_types = args
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ module PushType
2
+ module Templatable
3
+ extend ActiveSupport::Concern
4
+
5
+ def template
6
+ self.class.template_name
7
+ end
8
+
9
+ def template_args
10
+ [template, self.class.template_opts.except!(:path, :template)]
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ def template(name, opts = {})
16
+ @template_opts = opts.merge(template: name)
17
+ end
18
+
19
+ def template_name
20
+ File.join template_opts[:path], template_opts[:template]
21
+ end
22
+
23
+ def template_opts
24
+ {
25
+ path: 'nodes',
26
+ template: self.name.underscore
27
+ }.merge(@template_opts || {})
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ module PushType
2
+ module Trashable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :not_trash, -> { where(deleted_at: nil) }
7
+ scope :trashed, -> { where('deleted_at IS NOT NULL') }
8
+ end
9
+
10
+ def trash!
11
+ update_attribute :deleted_at, Time.zone.now
12
+ end
13
+
14
+ def restore!
15
+ update_attribute :deleted_at, nil
16
+ end
17
+
18
+ def trashed?
19
+ deleted_at.present?
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ module PushType
2
+ class Asset < ActiveRecord::Base
3
+
4
+ include PushType::Trashable
5
+
6
+ dragonfly_accessor :file
7
+
8
+ belongs_to :uploader, class_name: 'PushType::User'
9
+
10
+ validates :file, presence: true
11
+
12
+ default_scope { order(created_at: :desc) }
13
+
14
+ before_create :set_mime_type
15
+ after_destroy :destroy_file!
16
+
17
+ def kind
18
+ return nil unless file_stored?
19
+ case mime_type
20
+ when /\Aaudio\/.*\z/ then :audio
21
+ when /\Aimage\/.*\z/ then :image
22
+ when /\Avideo\/.*\z/ then :video
23
+ else :document
24
+ end
25
+ end
26
+
27
+ [:audio, :image, :video].each do |k|
28
+ define_method("#{k}?".to_sym) { kind == k }
29
+ end
30
+
31
+ def description_or_file_name
32
+ description? ? description : file_name
33
+ end
34
+
35
+ def preview_thumb_url(args = ['300x300#'])
36
+ return nil unless file_stored?
37
+ if image?
38
+ file.thumb(*args).url
39
+ else
40
+ "push_type/icon-file-#{ kind }.png"
41
+ end
42
+ end
43
+
44
+ def as_json(options = nil)
45
+ options = { only: [:id, :file_name, :file_size, :mime_type, :created_at], methods: [:new_record?, :image?, :description_or_file_name, :preview_thumb_url] } if options.empty?
46
+ super(options)
47
+ end
48
+
49
+ private
50
+
51
+ def set_mime_type
52
+ self.file_ext = file.ext
53
+ self.mime_type = file.mime_type
54
+ end
55
+
56
+ def destroy_file!
57
+ self.file.destroy!
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,57 @@
1
+ module PushType
2
+ class Node < ActiveRecord::Base
3
+
4
+ include PushType::FieldStore
5
+ include PushType::Nestable
6
+ include PushType::Templatable
7
+ include PushType::Trashable
8
+
9
+ belongs_to :creator, class_name: 'PushType::User'
10
+ belongs_to :updater, class_name: 'PushType::User'
11
+
12
+ enum status: [ :draft, :published ]
13
+
14
+ acts_as_tree name_column: 'slug', order: 'sort_order'
15
+
16
+ validates :title, presence: true
17
+ validates :slug, presence: true, uniqueness: { scope: :parent_id }
18
+
19
+ scope :published, -> {
20
+ not_trash.where(['push_type_nodes.status = ? AND push_type_nodes.published_at <= ?', Node.statuses[:published], Time.zone.now]).
21
+ where(['push_type_nodes.published_to IS NULL OR push_type_nodes.published_to > ?', Time.zone.now])
22
+ }
23
+
24
+ after_initialize :default_values
25
+ before_save :set_published_at
26
+
27
+ def permalink
28
+ @permalink ||= self_and_ancestors.map(&:slug).reverse.join('/')
29
+ end
30
+
31
+ def published?
32
+ super and !scheduled? and !expired?
33
+ end
34
+
35
+ def scheduled?
36
+ published_at? and published_at > Time.zone.now
37
+ end
38
+
39
+ def expired?
40
+ published_to? and published_to < Time.zone.now
41
+ end
42
+
43
+ private
44
+
45
+ def default_values
46
+ self.status ||= Node.statuses[:draft]
47
+ end
48
+
49
+ def set_published_at
50
+ case status
51
+ when 'draft', Node.statuses[:draft] then self.published_at = nil
52
+ when 'published', Node.statuses[:published] then self.published_at ||= Time.zone.now
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module PushType
2
+ class User < ActiveRecord::Base
3
+
4
+ include PushType::FieldStore
5
+
6
+ validates :name, presence: true
7
+ validates :email, presence: true, uniqueness: true
8
+
9
+ default_scope { order(:name) }
10
+
11
+ def initials
12
+ chunks = name ? name.split(' ') : []
13
+ chunks.slice!(1..-2)
14
+ chunks.map { |n| n[0] }.join.upcase
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PushType</title>
5
+ <%= stylesheet_link_tag "push_type/application", media: "all" %>
6
+ <%= javascript_include_tag "push_type/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,24 @@
1
+ # Configure
2
+ Dragonfly.app.configure do
3
+ plugin :imagemagick
4
+
5
+ secret "6fa0d3bcb6c44e897ca39a48eb86eb6262e4351bd0311674ff350ebaeb08c982"
6
+
7
+ url_format "/media/:job/:name"
8
+
9
+ datastore :file,
10
+ root_path: Rails.root.join('public/system/dragonfly', Rails.env),
11
+ server_root: Rails.root.join('public')
12
+ end
13
+
14
+ # Logger
15
+ Dragonfly.logger = Rails.logger
16
+
17
+ # Mount as middleware
18
+ Rails.application.middleware.use Dragonfly::Middleware
19
+
20
+ # Add model functionality
21
+ if defined?(ActiveRecord::Base)
22
+ ActiveRecord::Base.extend Dragonfly::Model
23
+ ActiveRecord::Base.extend Dragonfly::Model::Validations
24
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ PushType::Core::Engine.routes.draw do
2
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePushTypeUsers < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp')
4
+ create_table :push_type_users, id: :uuid, default: 'uuid_generate_v4()' do |t|
5
+ t.string :name
6
+ t.string :email
7
+ t.json :field_store
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ class CreatePushTypeNodes < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp')
4
+ create_table :push_type_nodes, id: :uuid, default: 'uuid_generate_v4()' do |t|
5
+ t.string :type
6
+ t.string :title
7
+ t.string :slug
8
+ t.json :field_store
9
+
10
+ t.uuid :parent_id
11
+ t.integer :sort_order
12
+
13
+ t.integer :status
14
+ t.datetime :published_at
15
+ t.datetime :published_to
16
+
17
+ t.uuid :creator_id
18
+ t.uuid :updater_id
19
+
20
+ t.timestamps
21
+ t.datetime :deleted_at
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ class CreatePushTypeNodeHierarchies < ActiveRecord::Migration
2
+ def change
3
+ create_table :push_type_node_hierarchies, id: false do |t|
4
+ t.uuid :ancestor_id, null: false
5
+ t.uuid :descendant_id, null: false
6
+ t.integer :generations, null: false
7
+ end
8
+
9
+ add_index :push_type_node_hierarchies, [:ancestor_id, :descendant_id, :generations],
10
+ unique: true,
11
+ name: "anc_desc_idx"
12
+
13
+ add_index :push_type_node_hierarchies, [:descendant_id],
14
+ name: "desc_idx"
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ class CreatePushTypeAssets < ActiveRecord::Migration
2
+ def change
3
+ enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp')
4
+ create_table :push_type_assets, id: :uuid, default: 'uuid_generate_v4()' do |t|
5
+ t.string :file_uid
6
+ t.string :file_name
7
+ t.integer :file_size
8
+ t.string :file_ext
9
+ t.string :mime_type
10
+ t.string :description
11
+
12
+ t.uuid :uploader_id
13
+
14
+ t.timestamps
15
+ t.datetime :deleted_at
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,56 @@
1
+ require "rails/generators/rails/app/app_generator"
2
+
3
+ module PushType
4
+ class PushType::DummyGenerator < Rails::Generators::Base
5
+ desc "Creates blank Rails application and installs PushType"
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ class_option :lib_name, default: 'push_type_core'
10
+ class_option :path, default: 'test/dummy'
11
+
12
+ def clean_up_test_dummy
13
+ remove_dir(dummy_path) if File.directory?(dummy_path)
14
+ end
15
+
16
+ PASSTHROUGH_OPTIONS = [
17
+ :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
18
+ ]
19
+
20
+ def generate_test_dummy
21
+ opts = {}.merge(options).slice(*PASSTHROUGH_OPTIONS)
22
+ opts[:database] = 'postgresql'
23
+ opts[:force] = true
24
+ opts[:skip_git] = true
25
+ opts[:skip_keeps] = true
26
+ opts[:skip_gemfile] = true
27
+ opts[:skip_bundle] = true
28
+
29
+ puts "Generating dummy Rails application... (#{options[:lib_name]})"
30
+ invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts
31
+ end
32
+
33
+ def test_dummy_config
34
+ template 'application.rb', "#{ dummy_path }/config/application.rb", force: true
35
+ copy_file 'boot.rb', "#{ dummy_path }/config/boot.rb", force: true
36
+ #copy_file 'page.rb', "#{ dummy_path }/app/models/page.rb", force: true
37
+ end
38
+
39
+ def clean_test_dummy
40
+ remove_file "#{ dummy_path }/test"
41
+ remove_file "#{ dummy_path }/vendor"
42
+ end
43
+
44
+ protected
45
+
46
+ def dummy_path
47
+ options[:path]
48
+ end
49
+
50
+ def lib_name
51
+ options[:lib_name]
52
+ end
53
+
54
+ end
55
+ end
56
+
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+
7
+ require '<%= lib_name %>'
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ config.action_mailer.default_url_options = { host: 'localhost:3000' }
12
+ end
13
+ end
14
+
@@ -0,0 +1,4 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
2
+
3
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
4
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,6 @@
1
+ class Page < PushType::Node
2
+
3
+ field :description
4
+ field :body, :rich_text, validates: { presence: true }
5
+
6
+ end
@@ -0,0 +1,28 @@
1
+ module PushType
2
+ class PushType::InstallGenerator < Rails::Generators::Base
3
+ desc "Install and configure PushType for this application"
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ class_option :migrate, type: :boolean, default: true
8
+
9
+ def create_push_type_initializer
10
+ copy_file 'push_type.rb', 'config/initializers/push_type.rb'
11
+ end
12
+
13
+ def inject_push_type_routes
14
+ inject_into_file 'config/routes.rb', "\n\n mount_push_type\n", after: 'Rails.application.routes.draw do', verbose: true
15
+ end
16
+
17
+ def install_migrations
18
+ rake 'railties:install:migrations'
19
+ end
20
+
21
+ def run_migrations
22
+ if options[:migrate]
23
+ rake 'db:migrate'
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ PushType.setup do |config|
2
+
3
+ config.root_node_types = :all
4
+
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a model that inherits from PushType::Node
3
+
4
+ Example:
5
+ rails generate push_type:node page
6
+
7
+ This will create:
8
+ app/models/page.rb
@@ -0,0 +1,12 @@
1
+ module PushType
2
+ class NodeGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_model
6
+ template 'node.rb', "app/models/#{ file_name }.rb"
7
+ template 'template.html.erb', "app/views/nodes/#{ file_name }.html.erb"
8
+ end
9
+
10
+ hook_for :test_framework, as: :model
11
+ end
12
+ end