push_type_core 0.1.0.beta3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/push_type/{field_store.rb → customizable.rb} +1 -1
- data/app/models/concerns/push_type/publishable.rb +43 -0
- data/app/models/concerns/push_type/templatable.rb +10 -8
- data/app/models/push_type/node.rb +3 -37
- data/app/models/push_type/user.rb +1 -1
- data/lib/generators/push_type/dummy/dummy_generator.rb +0 -1
- data/lib/generators/push_type/install/install_generator.rb +4 -2
- data/lib/push_type/core.rb +1 -1
- data/lib/push_type/field_type.rb +13 -4
- data/lib/push_type/testing/common_rake.rb +3 -3
- data/lib/push_type/testing/setup.rb +2 -1
- data/lib/push_type/testing/support/test_page.rb +2 -0
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/db/migrate/{20141205213452_create_push_type_users.push_type.rb → 20150102204403_create_push_type_users.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20141205213453_create_push_type_nodes.push_type.rb → 20150102204404_create_push_type_nodes.push_type.rb} +0 -0
- 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
- data/test/dummy/db/migrate/{20141205213455_create_push_type_assets.push_type.rb → 20150102204406_create_push_type_assets.push_type.rb} +0 -0
- data/test/dummy/db/schema.rb +1 -1
- data/test/dummy/log/test.log +1088 -908
- data/test/dummy/tmp/generators/app/models/home_page.rb +10 -0
- data/test/dummy/tmp/generators/app/views/nodes/home_page.html.erb +3 -0
- data/test/lib/generators/push_type/install_generator_test.rb +19 -0
- data/test/lib/generators/push_type/node_generator_test.rb +17 -0
- data/test/lib/push_type/core_test.rb +47 -0
- data/test/lib/push_type/field_type_test.rb +61 -0
- data/test/models/concerns/push_type/customizable_test.rb +30 -0
- data/test/models/concerns/push_type/nestable_test.rb +45 -0
- data/test/models/concerns/push_type/publishable_test.rb +74 -0
- data/test/models/concerns/push_type/templatable_test.rb +33 -0
- data/test/models/concerns/push_type/trashable_test.rb +32 -0
- data/test/models/push_type/node_test.rb +0 -65
- metadata +37 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c78eb41f1bdc82052b207a1e015c1eb0a03cbc6
|
4
|
+
data.tar.gz: 0bfac3128a8fbaab7007e912495eccfda36462c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3336cf790c4a8545de8e51965b092e202bf6b7f97a4cd639d5827bd08d9a8a3094799cf51dafdec57393dbfea23ac0c8331b3d5e29d209d03b16703387f1b512
|
7
|
+
data.tar.gz: 5095723274533fb6e50141db537051c003f00908a8b7d1aa9d9c2bf37ee547bb4ee3cb3c4e8075f2a89d306f896f32bde6e7421b51847f39fa587846dde15054
|
@@ -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.
|
6
|
+
self.class.template_path
|
7
7
|
end
|
8
8
|
|
9
9
|
def template_args
|
10
|
-
[template, self.class.template_opts.except!(:path
|
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
|
-
@
|
16
|
+
@template_name = name
|
17
|
+
@template_opts = opts
|
17
18
|
end
|
18
19
|
|
19
20
|
def template_name
|
20
|
-
|
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::
|
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
|
@@ -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
|
-
|
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
|
-
|
24
|
+
say_status :running, 'migrations'
|
25
|
+
quietly { rake 'db:migrate' }
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
data/lib/push_type/core.rb
CHANGED
data/lib/push_type/field_type.rb
CHANGED
@@ -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(/
|
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.
|
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] }",
|
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 [
|
14
|
-
PushType::NodeGenerator.start [
|
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 = :
|
6
|
+
DatabaseCleaner.strategy = :transaction
|
7
|
+
DatabaseCleaner.clean_with :truncation
|
7
8
|
Dragonfly.app.use_datastore :memory
|
8
9
|
|
9
10
|
class ActiveSupport::TestCase
|
@@ -11,10 +11,10 @@
|
|
11
11
|
# if you're sharing your code publicly.
|
12
12
|
|
13
13
|
development:
|
14
|
-
secret_key_base:
|
14
|
+
secret_key_base: 008a08469af29400dc99be0048b9a9ec9285d1b0f980103d94bc705f4c2caae79baa43cc22b32ac3ad095775cfec902a338a037157104ea45bfd3a0b1a597c70
|
15
15
|
|
16
16
|
test:
|
17
|
-
secret_key_base:
|
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.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/dummy/db/schema.rb
CHANGED
@@ -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:
|
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"
|