push_type_core 0.9.5 → 0.10.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/app/controllers/concerns/push_type/filterable.rb +12 -27
- data/app/controllers/front_end_controller.rb +3 -3
- data/app/helpers/push_type/media_url_helper.rb +25 -0
- data/app/helpers/push_type/node_url_helper.rb +15 -0
- data/app/models/concerns/push_type/nestable.rb +14 -0
- data/app/views/push_type/setup.html.erb +1 -3
- data/lib/generators/push_type/install/install_generator.rb +19 -1
- data/lib/push_type/core/engine.rb +13 -2
- data/lib/push_type/core.rb +15 -1
- data/lib/push_type/rails/routes.rb +26 -19
- data/lib/push_type/testing/setup.rb +0 -4
- data/lib/push_type/version.rb +1 -1
- data/test/controllers/front_end_controller_test.rb +4 -2
- data/test/dummy/config/initializers/push_type.rb +1 -1
- data/test/dummy/config/routes.rb +10 -1
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/db/schema.rb +1 -1
- data/test/dummy/log/test.log +7791 -7607
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/VT/VT0xDh7gu1K3uYidKny01QY0vyaeQDbHoPICVlZmQQc.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/YC/YCmmKydZG1FxHcFZiHcaSZhbT44fV2vJglp5i1fOvAc.cache +0 -0
- data/test/dummy/tmp/generators/config/initializers/push_type.rb +50 -0
- data/test/dummy/tmp/generators/config/routes.rb +15 -0
- data/test/helpers/push_type/media_url_helper_test.rb +32 -0
- data/test/helpers/push_type/node_url_helper_test.rb +19 -0
- data/test/lib/push_type/core_test.rb +1 -1
- data/test/models/concerns/push_type/nestable_test.rb +20 -0
- data/test/models/push_type/node_test.rb +4 -4
- metadata +30 -24
- data/test/dummy/tmp/generators/app/models/home_page.rb +0 -12
- data/test/dummy/tmp/generators/app/views/nodes/home_page.html.erb +0 -13
- /data/test/dummy/db/migrate/{20161024153920_create_push_type_users.push_type.rb → 20161116222801_create_push_type_users.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20161024153921_create_push_type_nodes.push_type.rb → 20161116222802_create_push_type_nodes.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20161024153922_create_push_type_node_hierarchies.push_type.rb → 20161116222803_create_push_type_node_hierarchies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20161024153923_create_push_type_assets.push_type.rb → 20161116222804_create_push_type_assets.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20161024153924_add_field_store_default_values.push_type.rb → 20161116222805_add_field_store_default_values.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20161024153925_drop_legacy_push_type_taxonomies.push_type.rb → 20161116222806_drop_legacy_push_type_taxonomies.push_type.rb} +0 -0
- /data/test/dummy/tmp/cache/assets/sprockets/v3.0/{o_/o_sN8dpdlBAPBdNlPQdGh2ZlzC13OFBPyj6CC2iAQ6g.cache → 3D/3DiLOA9ufk-bm1-9-hOFWYmGKMgJWxv8xBbSS2pKDN4.cache} +0 -0
- /data/test/dummy/tmp/cache/assets/sprockets/v3.0/{A8/A8KFzRgbkc1okm6dqN_A9dp76mPyemmS15wUg70Kr2U.cache → tn/tnKqEfyTQNEMuWAhX3xym0TbSoUwIe8XlKbKLmN8oPA.cache} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fd6cd0064cd63d1dd950087f1ac29d726f4c008
|
4
|
+
data.tar.gz: 7f4324b860c06b86ca5544bbe74483228e9109ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d6b466d5f153fd3175aaa49d8730a4dd72e4d9936d69ceef3da9283570859f57d26dec1e801a0870ae28698efd0c49a9d7f9baff867364f19c5b781f78ce451
|
7
|
+
data.tar.gz: fce3f8f57b3a02994a556a3dae73b6ecaec3c9206ca314ff1f12d013bc9e49a7e9e71c5e252d0b26204187c526681d01554e5ec96714ca0930062a292107004c
|
data/LICENSE.md
CHANGED
@@ -4,32 +4,20 @@ module PushType
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
def filter_scope
|
8
|
-
self.class.filter_scope
|
9
|
-
end
|
10
|
-
|
11
|
-
def filter_obj
|
12
|
-
instance_variable_get "@#{ filter_scope }"
|
13
|
-
end
|
14
|
-
|
15
|
-
def filter_obj_type
|
16
|
-
filter_obj.type.underscore.to_sym
|
17
|
-
end
|
18
|
-
|
19
7
|
def before_load_filters
|
20
|
-
filters = self.send("
|
21
|
-
filters.each { |f|
|
8
|
+
filters = self.send("before_node_load_filters")
|
9
|
+
filters.each { |f| run_node_filter(*f) } unless filters.blank?
|
22
10
|
end
|
23
11
|
|
24
12
|
def around_action_filters
|
25
|
-
before_filters = self.send("
|
26
|
-
before_filters.each { |f|
|
13
|
+
before_filters = self.send("before_node_action_filters")
|
14
|
+
before_filters.each { |f| run_node_filter(*f) } unless before_filters.blank?
|
27
15
|
yield
|
28
|
-
after_filters = self.send("
|
29
|
-
after_filters.each { |f|
|
16
|
+
after_filters = self.send("after_node_action_filters")
|
17
|
+
after_filters.each { |f| run_node_filter(*f) } unless after_filters.blank?
|
30
18
|
end
|
31
19
|
|
32
|
-
def
|
20
|
+
def run_node_filter(*args)
|
33
21
|
methods_or_proc, opts = case args.last
|
34
22
|
when Proc then args.first.is_a?(Hash) ? [ args.last, args.first ] : [ args.last, {} ]
|
35
23
|
when Hash then [ args[0..-2], args.last ]
|
@@ -46,21 +34,18 @@ module PushType
|
|
46
34
|
end
|
47
35
|
|
48
36
|
def filter_obj_in(types)
|
49
|
-
types &&
|
37
|
+
types && @node && Array(types).include?(@node.type.underscore.to_sym)
|
50
38
|
end
|
51
39
|
|
52
40
|
def filter_obj_not_in(types)
|
53
|
-
types &&
|
41
|
+
types && @node && !Array(types).include?(@node.type.underscore.to_sym)
|
54
42
|
end
|
55
43
|
|
56
44
|
module ClassMethods
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@filter_scope = sym
|
62
|
-
prepend_before_action :before_load_filters, opts
|
63
|
-
around_action :around_action_filters, opts
|
46
|
+
def node_filters
|
47
|
+
prepend_before_action :before_load_filters
|
48
|
+
around_action :around_action_filters
|
64
49
|
end
|
65
50
|
|
66
51
|
end
|
@@ -3,7 +3,7 @@ class FrontEndController < ApplicationController
|
|
3
3
|
include PushType::Filterable
|
4
4
|
|
5
5
|
before_action :load_node, only: :show
|
6
|
-
|
6
|
+
node_filters
|
7
7
|
|
8
8
|
def show
|
9
9
|
render *@node.template_args
|
@@ -17,7 +17,7 @@ class FrontEndController < ApplicationController
|
|
17
17
|
|
18
18
|
def raise_404
|
19
19
|
if root_path?
|
20
|
-
render template: 'push_type/setup', layout:
|
20
|
+
render template: 'push_type/setup', layout: nil, status: 404
|
21
21
|
else
|
22
22
|
raise ActiveRecord::RecordNotFound
|
23
23
|
end
|
@@ -32,4 +32,4 @@ class FrontEndController < ApplicationController
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PushType
|
2
|
+
module MediaUrlHelper
|
3
|
+
|
4
|
+
URI_REGEXP = %r{^https?://}i
|
5
|
+
|
6
|
+
def media_path(source, options = {})
|
7
|
+
file_uid = source.try(:file_uid) || source
|
8
|
+
path = main_app.media_path(file_uid, options)
|
9
|
+
|
10
|
+
if host = compute_asset_host(path, options)
|
11
|
+
url = File.join(host, path)
|
12
|
+
else
|
13
|
+
path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def media_url(source, options = {})
|
18
|
+
file_uid = source.try(:file_uid) || source
|
19
|
+
path = media_path(source)
|
20
|
+
return path if path =~ URI_REGEXP
|
21
|
+
main_app.media_url(file_uid, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PushType
|
2
|
+
module NodeUrlHelper
|
3
|
+
|
4
|
+
def node_path(source, options = {})
|
5
|
+
permalink = source.try(:permalink) || source
|
6
|
+
main_app.node_path(permalink, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def node_url(source, options = {})
|
10
|
+
permalink = source.try(:permalink) || source
|
11
|
+
main_app.node_url(permalink, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -2,6 +2,10 @@ module PushType
|
|
2
2
|
module Nestable
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
included do
|
6
|
+
validate :parent_accepts_child
|
7
|
+
end
|
8
|
+
|
5
9
|
def child_nodes
|
6
10
|
self.class.child_nodes
|
7
11
|
end
|
@@ -23,6 +27,16 @@ module PushType
|
|
23
27
|
super.reorder(self.class.child_order)
|
24
28
|
end
|
25
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
def parent_accepts_child
|
33
|
+
if parent_id.present?
|
34
|
+
unless parent.child_nodes.include?(self.class.name.underscore)
|
35
|
+
errors.add :parent_id, 'does not accept this child'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
module ClassMethods
|
27
41
|
|
28
42
|
attr_reader :child_order
|
@@ -116,14 +116,12 @@
|
|
116
116
|
<% end %>
|
117
117
|
<li>
|
118
118
|
<span class="label text">And log in:</span>
|
119
|
-
<div><%= link_to
|
119
|
+
<div><%= link_to push_type_admin.root_url, push_type_admin.root_path %></div>
|
120
120
|
</li>
|
121
121
|
</ol>
|
122
122
|
|
123
123
|
</div>
|
124
124
|
</div>
|
125
125
|
|
126
|
-
|
127
|
-
|
128
126
|
</body>
|
129
127
|
</html>
|
@@ -11,7 +11,7 @@ module PushType
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def inject_push_type_routes
|
14
|
-
inject_into_file 'config/routes.rb', "\n\n
|
14
|
+
inject_into_file 'config/routes.rb', "\n\n#{ mount_heredoc }", after: 'Rails.application.routes.draw do', verbose: true
|
15
15
|
end
|
16
16
|
|
17
17
|
def install_migrations
|
@@ -26,5 +26,23 @@ module PushType
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
private
|
30
|
+
|
31
|
+
def mount_heredoc
|
32
|
+
<<-EOF.gsub /^\s+/, ' '
|
33
|
+
# Mount all the registered PushType Rails Engines. This should be placed
|
34
|
+
# at the end of your routes.rb file to ensure your application routes are
|
35
|
+
# not overidden by PushType.
|
36
|
+
#
|
37
|
+
# Overide the default mount points by passing a hash of options.
|
38
|
+
# Example:
|
39
|
+
#
|
40
|
+
# mount_push_type admin: 'cms', front_end: 'blog'
|
41
|
+
#
|
42
|
+
mount_push_type
|
43
|
+
|
44
|
+
EOF
|
45
|
+
end
|
46
|
+
|
29
47
|
end
|
30
48
|
end
|
@@ -25,13 +25,24 @@ module PushType
|
|
25
25
|
end
|
26
26
|
|
27
27
|
initializer 'push_type.application_controller' do
|
28
|
-
ActiveSupport.on_load
|
28
|
+
ActiveSupport.on_load :action_controller do
|
29
29
|
include PushType::ApplicationControllerMethods
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
initializer 'push_type.url_helpers' do
|
34
|
+
ActiveSupport.on_load :action_controller do
|
35
|
+
helper PushType::MediaUrlHelper
|
36
|
+
helper PushType::NodeUrlHelper
|
37
|
+
end
|
38
|
+
ActiveSupport.on_load :action_view do
|
39
|
+
include PushType::MediaUrlHelper
|
40
|
+
include PushType::NodeUrlHelper
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
33
44
|
initializer 'push_type.menu_helpers' do
|
34
|
-
ActiveSupport.on_load
|
45
|
+
ActiveSupport.on_load :action_view do
|
35
46
|
include PushType::MenuBuilder::Helpers
|
36
47
|
end
|
37
48
|
end
|
data/lib/push_type/core.rb
CHANGED
@@ -52,10 +52,24 @@ module PushType
|
|
52
52
|
PushType::MenuBuilder.select(key, &block)
|
53
53
|
end
|
54
54
|
|
55
|
+
def register_engine(mod, opts = {})
|
56
|
+
opts[:load_hook] ||= mod.to_s.underscore.gsub(/\//, '_').to_sym
|
57
|
+
|
58
|
+
if opts[:mount]
|
59
|
+
rails_engines[opts[:load_hook]] = [mod, opts[:mount]]
|
60
|
+
end
|
61
|
+
|
62
|
+
ActiveSupport.run_load_hooks(opts[:load_hook], PushType)
|
63
|
+
end
|
64
|
+
|
65
|
+
def rails_engines
|
66
|
+
@rails_engines ||= {}
|
67
|
+
end
|
68
|
+
|
55
69
|
end
|
56
70
|
|
57
71
|
module Core
|
58
|
-
|
72
|
+
PushType.register_engine self
|
59
73
|
end
|
60
74
|
|
61
75
|
end
|
@@ -1,28 +1,35 @@
|
|
1
1
|
module ActionDispatch::Routing
|
2
2
|
class Mapper
|
3
3
|
|
4
|
-
def mount_push_type(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}.deep_merge!(options)
|
4
|
+
def mount_push_type(opts = {})
|
5
|
+
# Mount the registered PushType engines at the specified path.
|
6
|
+
PushType.rails_engines.each do |k, (mod, default_path)|
|
7
|
+
key = push_type_engine_keys[k] || k
|
8
|
+
path = opts[key] || default_path
|
9
|
+
mount mod::Engine => path
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
scope path: opts[:front_end] do
|
13
|
+
# Use a Dragonfly endpoint to provide better URLs for accessing assets
|
14
|
+
get 'media/*file_uid' => Dragonfly.app.endpoint { |params, app|
|
15
|
+
file_name = [ params[:file_uid], params[:format] ].join('.')
|
16
|
+
asset = PushType::Asset.find_by_file_uid! file_name
|
17
|
+
asset.media params[:style]
|
18
|
+
}, as: 'media'
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
# A catch-all root for the nodes
|
21
|
+
get '*permalink' => 'front_end#show', as: 'node'
|
22
|
+
get '/' => 'front_end#show', as: 'home', permalink: PushType.config.home_slug if PushType.config.home_slug.present?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
def push_type_engine_keys
|
29
|
+
{
|
30
|
+
push_type_api: :api,
|
31
|
+
push_type_admin: :admin
|
32
|
+
}
|
26
33
|
end
|
27
34
|
|
28
35
|
end
|
@@ -30,10 +30,6 @@ class ActiveSupport::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
class ActionController::TestCase
|
33
|
-
before :each do
|
34
|
-
@routes = PushType::Core::Engine.routes
|
35
|
-
end
|
36
|
-
|
37
33
|
if Rails.version.to_f >= 5
|
38
34
|
require 'rails-controller-testing'
|
39
35
|
include ::Rails::Controller::Testing::TestProcess
|
data/lib/push_type/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class FrontEndControllerTest < ActionController::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
before { @routes = Rails.application.routes }
|
6
|
-
|
6
|
+
|
7
7
|
describe 'GET #show' do
|
8
8
|
let(:page) { Page.create attributes }
|
9
9
|
let(:permalink) { page.permalink }
|
@@ -28,6 +28,7 @@ class FrontEndControllerTest < ActionController::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'node filters' do
|
31
|
+
|
31
32
|
ApplicationController.module_eval do
|
32
33
|
before_node_load { @foo = {} }
|
33
34
|
before_node_action { @foo[:node_action] = true }
|
@@ -44,6 +45,7 @@ class FrontEndControllerTest < ActionController::TestCase
|
|
44
45
|
@foo[:test_2] = true
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
47
49
|
let(:page) { FactoryGirl.create :published_node, type: 'Page' }
|
48
50
|
before { get :show, params: { permalink: page.permalink } }
|
49
51
|
it { assigns[:foo].must_be_instance_of Hash }
|
@@ -45,6 +45,6 @@ PushType.setup do |config|
|
|
45
45
|
# secret_access_key: ENV['SECRET_ACCESS_KEY_ID']
|
46
46
|
# }
|
47
47
|
|
48
|
-
# config.dragonfly_secret = '
|
48
|
+
# config.dragonfly_secret = 'db0e7c33e8b359951d22f8e750068f5c5896b6adfa07cbb839b895550378c153'
|
49
49
|
|
50
50
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
+
# Mount all the registered PushType Rails Engines. This should be placed
|
4
|
+
# at the end of your routes.rb file to ensure your application routes are
|
5
|
+
# not overidden by PushType.
|
6
|
+
#
|
7
|
+
# Overide the default mount points by passing a hash of options.
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# mount_push_type admin: 'cms', front_end: 'blog'
|
11
|
+
#
|
3
12
|
mount_push_type
|
4
|
-
|
13
|
+
|
5
14
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
6
15
|
end
|
@@ -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: a3f3c85b457a43f7bc749ac36a23dfbe8c276f37e549629681d926ddc777a60b1de8b51423b7eeb88d83cf12899d57df2874e8764ff2658f1b4c25ef71d1e5c2
|
15
15
|
|
16
16
|
test:
|
17
|
-
secret_key_base:
|
17
|
+
secret_key_base: 733f6bf04272401ea3a441bf8371d6075c2a60649e4b9360bdd7c6130bc0d262b40adf47d0176794d8404c08badc03339b814841f132c92e06285db7583746c9
|
18
18
|
|
19
19
|
# Do not keep production secrets in the repository,
|
20
20
|
# instead read values from the environment.
|
data/test/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 20161116222806) do
|
14
14
|
|
15
15
|
# These are extensions that must be enabled in order to support this database
|
16
16
|
enable_extension "plpgsql"
|