push_type_core 0.1.0.beta3 → 0.1.0

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/push_type/{field_store.rb → customizable.rb} +1 -1
  3. data/app/models/concerns/push_type/publishable.rb +43 -0
  4. data/app/models/concerns/push_type/templatable.rb +10 -8
  5. data/app/models/push_type/node.rb +3 -37
  6. data/app/models/push_type/user.rb +1 -1
  7. data/lib/generators/push_type/dummy/dummy_generator.rb +0 -1
  8. data/lib/generators/push_type/install/install_generator.rb +4 -2
  9. data/lib/push_type/core.rb +1 -1
  10. data/lib/push_type/field_type.rb +13 -4
  11. data/lib/push_type/testing/common_rake.rb +3 -3
  12. data/lib/push_type/testing/setup.rb +2 -1
  13. data/lib/push_type/testing/support/test_page.rb +2 -0
  14. data/test/dummy/config/secrets.yml +2 -2
  15. data/test/dummy/db/migrate/{20141205213452_create_push_type_users.push_type.rb → 20150102204403_create_push_type_users.push_type.rb} +0 -0
  16. data/test/dummy/db/migrate/{20141205213453_create_push_type_nodes.push_type.rb → 20150102204404_create_push_type_nodes.push_type.rb} +0 -0
  17. data/test/dummy/db/migrate/{20141205213454_create_push_type_node_hierarchies.push_type.rb → 20150102204405_create_push_type_node_hierarchies.push_type.rb} +0 -0
  18. data/test/dummy/db/migrate/{20141205213455_create_push_type_assets.push_type.rb → 20150102204406_create_push_type_assets.push_type.rb} +0 -0
  19. data/test/dummy/db/schema.rb +1 -1
  20. data/test/dummy/log/test.log +1088 -908
  21. data/test/dummy/tmp/generators/app/models/home_page.rb +10 -0
  22. data/test/dummy/tmp/generators/app/views/nodes/home_page.html.erb +3 -0
  23. data/test/lib/generators/push_type/install_generator_test.rb +19 -0
  24. data/test/lib/generators/push_type/node_generator_test.rb +17 -0
  25. data/test/lib/push_type/core_test.rb +47 -0
  26. data/test/lib/push_type/field_type_test.rb +61 -0
  27. data/test/models/concerns/push_type/customizable_test.rb +30 -0
  28. data/test/models/concerns/push_type/nestable_test.rb +45 -0
  29. data/test/models/concerns/push_type/publishable_test.rb +74 -0
  30. data/test/models/concerns/push_type/templatable_test.rb +33 -0
  31. data/test/models/concerns/push_type/trashable_test.rb +32 -0
  32. data/test/models/push_type/node_test.rb +0 -65
  33. metadata +37 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e5cfc57c3068c45c73376c6905e192f03321f06
4
- data.tar.gz: 04013f98749da8c8a5be4902c7041fbae14c79d5
3
+ metadata.gz: 5c78eb41f1bdc82052b207a1e015c1eb0a03cbc6
4
+ data.tar.gz: 0bfac3128a8fbaab7007e912495eccfda36462c6
5
5
  SHA512:
6
- metadata.gz: 291069e98b7024375031e14c0abfd2aec2d01e904c2e24ac9fbb1a011b5f1ca91a04a917c8e85c567f5d267e88599ed3e8d69c08a5fe369903938b3198776ab5
7
- data.tar.gz: 7eb951c044e25becd8ce2764713aec11e669b43d4cc5a9308adae8c8ee23063cf3585f7f5c617379878cbeb0eab108c42e75a16268341c26b46a64437ad45fdc
6
+ metadata.gz: 3336cf790c4a8545de8e51965b092e202bf6b7f97a4cd639d5827bd08d9a8a3094799cf51dafdec57393dbfea23ac0c8331b3d5e29d209d03b16703387f1b512
7
+ data.tar.gz: 5095723274533fb6e50141db537051c003f00908a8b7d1aa9d9c2bf37ee547bb4ee3cb3c4e8075f2a89d306f896f32bde6e7421b51847f39fa587846dde15054
@@ -1,5 +1,5 @@
1
1
  module PushType
2
- module FieldStore
2
+ module Customizable
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def fields
@@ -0,0 +1,43 @@
1
+ module PushType
2
+ module Publishable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ enum status: [ :draft, :published ]
7
+
8
+ scope :published, -> {
9
+ not_trash.where(['push_type_nodes.status = ? AND push_type_nodes.published_at <= ?', self.statuses[:published], Time.zone.now]).
10
+ where(['push_type_nodes.published_to IS NULL OR push_type_nodes.published_to > ?', Time.zone.now])
11
+ }
12
+
13
+ after_initialize :set_default_status
14
+ before_save :set_published_at
15
+
16
+ def published?
17
+ super and !scheduled? and !expired?
18
+ end
19
+ end
20
+
21
+ def scheduled?
22
+ published_at? and published_at > Time.zone.now
23
+ end
24
+
25
+ def expired?
26
+ published_to? and published_to < Time.zone.now
27
+ end
28
+
29
+ private
30
+
31
+ def set_published_at
32
+ case status
33
+ when 'draft', self.class.statuses[:draft] then self.published_at = nil
34
+ when 'published', self.class.statuses[:published] then self.published_at ||= Time.zone.now
35
+ end
36
+ end
37
+
38
+ def set_default_status
39
+ self.status ||= self.class.statuses[:draft]
40
+ end
41
+
42
+ end
43
+ end
@@ -3,28 +3,30 @@ module PushType
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def template
6
- self.class.template_name
6
+ self.class.template_path
7
7
  end
8
8
 
9
9
  def template_args
10
- [template, self.class.template_opts.except!(:path, :template)]
10
+ [template, self.class.template_opts.except!(:path)]
11
11
  end
12
12
 
13
13
  module ClassMethods
14
14
 
15
15
  def template(name, opts = {})
16
- @template_opts = opts.merge(template: name)
16
+ @template_name = name
17
+ @template_opts = opts
17
18
  end
18
19
 
19
20
  def template_name
20
- File.join template_opts[:path], template_opts[:template]
21
+ @template_name || self.name.underscore
22
+ end
23
+
24
+ def template_path
25
+ File.join template_opts[:path], template_name
21
26
  end
22
27
 
23
28
  def template_opts
24
- {
25
- path: 'nodes',
26
- template: self.name.underscore
27
- }.merge(@template_opts || {})
29
+ { path: 'nodes' }.merge(@template_opts || {})
28
30
  end
29
31
 
30
32
  end
@@ -1,57 +1,23 @@
1
1
  module PushType
2
2
  class Node < ActiveRecord::Base
3
3
 
4
- include PushType::FieldStore
4
+ include PushType::Customizable
5
5
  include PushType::Nestable
6
6
  include PushType::Templatable
7
+ include PushType::Publishable
7
8
  include PushType::Trashable
8
9
 
9
10
  belongs_to :creator, class_name: 'PushType::User'
10
11
  belongs_to :updater, class_name: 'PushType::User'
11
12
 
12
- enum status: [ :draft, :published ]
13
-
14
13
  acts_as_tree name_column: 'slug', order: 'sort_order'
15
14
 
16
15
  validates :title, presence: true
17
16
  validates :slug, presence: true, uniqueness: { scope: :parent_id }
18
17
 
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
18
  def permalink
28
19
  @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
20
+ end
55
21
 
56
22
  end
57
23
  end
@@ -1,7 +1,7 @@
1
1
  module PushType
2
2
  class User < ActiveRecord::Base
3
3
 
4
- include PushType::FieldStore
4
+ include PushType::Customizable
5
5
 
6
6
  validates :name, presence: true
7
7
  validates :email, presence: true, uniqueness: true
@@ -33,7 +33,6 @@ module PushType
33
33
  def test_dummy_config
34
34
  template 'application.rb', "#{ dummy_path }/config/application.rb", force: true
35
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
36
  end
38
37
 
39
38
  def clean_test_dummy
@@ -15,12 +15,14 @@ module PushType
15
15
  end
16
16
 
17
17
  def install_migrations
18
- rake 'railties:install:migrations'
18
+ say_status :copying, 'migrations'
19
+ quietly { rake 'railties:install:migrations' }
19
20
  end
20
21
 
21
22
  def run_migrations
22
23
  if options[:migrate]
23
- rake 'db:migrate'
24
+ say_status :running, 'migrations'
25
+ quietly { rake 'db:migrate' }
24
26
  end
25
27
  end
26
28
 
@@ -30,7 +30,7 @@ module PushType
30
30
  false
31
31
  end
32
32
  end
33
- end
33
+ end.sort
34
34
  end
35
35
  end
36
36
 
@@ -3,13 +3,13 @@ module PushType
3
3
 
4
4
  attr_reader :name
5
5
 
6
- def initialize(name, opts)
7
- @name = name
6
+ def initialize(name, opts = {})
7
+ @name = name.to_s
8
8
  @opts = opts
9
9
  end
10
10
 
11
11
  def kind
12
- self.class.name.demodulize.underscore.gsub(/_field$/, '')
12
+ self.class.name.demodulize.underscore.gsub(/_(field|type)$/, '')
13
13
  end
14
14
 
15
15
  def template
@@ -17,7 +17,7 @@ module PushType
17
17
  end
18
18
 
19
19
  def label
20
- @opts[:label] || name.to_s.humanize
20
+ @opts[:label] || name.humanize
21
21
  end
22
22
 
23
23
  def html_options
@@ -28,6 +28,15 @@ module PushType
28
28
  @opts[:form_helper] || :text_field
29
29
  end
30
30
 
31
+ def column_class
32
+ case @opts[:colspan]
33
+ when 2 then 'medium-6'
34
+ when 3 then 'medium-4'
35
+ when 3 then 'medium-3'
36
+ else nil
37
+ end
38
+ end
39
+
31
40
  def to_json(val)
32
41
  val.to_s
33
42
  end
@@ -7,11 +7,11 @@ namespace :common do
7
7
  task :test_app, :lib_name, :base_path, :dummy_path do |t, args|
8
8
  args.with_defaults lib_name: 'push_type_core', base_path: './', dummy_path: 'test/dummy'
9
9
 
10
- PushType::DummyGenerator.start ["--lib_name=#{ args[:lib_name] }", "--path=#{ args[:dummy_path] }", "--quiet"]
10
+ PushType::DummyGenerator.start ["--lib_name=#{ args[:lib_name] }", "--path=#{ args[:dummy_path] }", '--quiet']
11
11
 
12
12
  Dir.chdir File.join(args[:base_path], args[:dummy_path]) do
13
- PushType::InstallGenerator.start ["--migrate=false", "--quiet"]
14
- PushType::NodeGenerator.start ["page", "--quiet"]
13
+ PushType::InstallGenerator.start ['--migrate=false', '--quiet']
14
+ PushType::NodeGenerator.start ['page', '--quiet']
15
15
  system 'bundle exec rake db:drop db:create db:migrate'
16
16
  end
17
17
  end
@@ -3,7 +3,8 @@ require 'database_cleaner'
3
3
  # Load support files
4
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5
5
 
6
- DatabaseCleaner.strategy = :truncation
6
+ DatabaseCleaner.strategy = :transaction
7
+ DatabaseCleaner.clean_with :truncation
7
8
  Dragonfly.app.use_datastore :memory
8
9
 
9
10
  class ActiveSupport::TestCase
@@ -0,0 +1,2 @@
1
+ class TestPage < PushType::Node
2
+ end
@@ -11,10 +11,10 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: 3a0290ef14a6709a4ddf47900c48071388eeda0043cfa62d5c91bd7ca43b4c67b6d75e8581c2e8f59c8602bec6c02704f464bb595f03d40c41854c09cf750425
14
+ secret_key_base: 008a08469af29400dc99be0048b9a9ec9285d1b0f980103d94bc705f4c2caae79baa43cc22b32ac3ad095775cfec902a338a037157104ea45bfd3a0b1a597c70
15
15
 
16
16
  test:
17
- secret_key_base: 67677cecd4f711470d4f4d987ce44bafe748709944949b14510c709115e2110a45ab5afdfd35eddc238bd36f5f181528d6923a1c099ac02d1699c2a808e25f51
17
+ secret_key_base: 05838fc140f2e78a6e755907d2518a78c7c826431bb4bb4552183478d798ec56053fa09f29ddb5c3eac83d073f6ee10b84c522cda9a7c6584c603aa254b988de
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20141205213455) do
14
+ ActiveRecord::Schema.define(version: 20150102204406) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"