push_type_core 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 027e8e1c338edaa1fbc4b8fabb37328db231b35f
4
- data.tar.gz: 006c080eab42cc183f85fffcccf8067a86e85d1f
3
+ metadata.gz: 4248b67982fe778388b3418614a95043834315ce
4
+ data.tar.gz: 5d64098c0f00b7d3aad9a7dabd151e4eff907abc
5
5
  SHA512:
6
- metadata.gz: 6807bd9745cf1937350e426f2cff294c61c2221070417fdbf464a4038dcb4a90752a6bc55a81918a92a6f8bb721157e735eafe95289b7cd2d9b585b2843adf3c
7
- data.tar.gz: bf37b3cff59b95aa6f734df9224e0353cf407429be57b595a44da0b1fa43c39d7cdbd8f754360f761b2bb8bbec3ba65f7c4fc9158ecf483059ccddb3c6d8f62c
6
+ metadata.gz: e953d4035fca92bd4f5deeaf4b7cb7f0374071c49f34c423fae5b6c8cc373e595c896c88aa58ea084d69f4083fbea71de6d85f284518b1ddfc9cb34ea17a5877
7
+ data.tar.gz: 54c2ef9df08874ee1f59fac6682e1158e4db7d868b1f9de4a34d3699c52c96b842e1d61eb9885fd5a8389eb650754646080e992babf2cbb8038594abe5cd5bd6
@@ -0,0 +1,18 @@
1
+ module PushType
2
+ module ApplicationControllerMethods
3
+ extend ActiveSupport::Concern
4
+
5
+ protected
6
+
7
+ def permalink_path
8
+ params[:permalink].split('/')
9
+ end
10
+
11
+ private
12
+
13
+ def node_hook(method)
14
+ send(method) if self.class.method_defined?(method.to_sym)
15
+ end
16
+
17
+ end
18
+ end
@@ -1,6 +1,7 @@
1
1
  class FrontEndController < ApplicationController
2
2
 
3
- before_filter :load_node, only: :node
3
+ before_action :before_load, :load_node, :before_node, only: :node
4
+ after_action :after_node, only: :node
4
5
 
5
6
  def node
6
7
  render *@node.template_args
@@ -9,13 +10,25 @@ class FrontEndController < ApplicationController
9
10
  private
10
11
 
11
12
  def load_node
12
- @node = PushType::Node.published.find_by_path permalink_parts
13
+ @node = PushType::Node.published.find_by_path permalink_path
13
14
  raise ActiveRecord::RecordNotFound unless @node
14
15
  instance_variable_set "@#{ @node.type.underscore }", @node
15
16
  end
16
17
 
17
- def permalink_parts
18
- params[:permalink].split('/')
18
+ def before_load
19
+ node_hook(:before_node_load)
20
+ end
21
+
22
+ def node_types_array
23
+ ['node', @node.type.underscore]
24
+ end
25
+
26
+ def before_node
27
+ node_types_array.each { |kind| node_hook(:"before_#{ kind }_action") }
28
+ end
29
+
30
+ def after_node
31
+ node_types_array.each { |kind| node_hook(:"after_#{ kind }_action") }
19
32
  end
20
33
 
21
34
  end
@@ -14,12 +14,14 @@ module PushType
14
14
 
15
15
  config.to_prepare do
16
16
  Rails.application.eager_load! unless Rails.application.config.cache_classes
17
+ ApplicationController.send :include, PushType::ApplicationControllerMethods
17
18
  end
18
19
 
19
20
  initializer 'push_type.dragonfly_config' do
20
21
  PushType.config.dragonfly_secret ||= Rails.application.secrets.secret_key_base
21
22
  PushType.dragonfly_app_setup!
22
23
  end
24
+
23
25
  end
24
26
  end
25
27
  end
@@ -5,6 +5,10 @@ module PushType
5
5
 
6
6
  class << self
7
7
 
8
+ def version
9
+ PushType::VERSION
10
+ end
11
+
8
12
  def config
9
13
  PushType::Config
10
14
  end
@@ -56,3 +60,4 @@ require 'push_type/config'
56
60
  require 'push_type/core/engine'
57
61
  require 'push_type/rails/routes'
58
62
  require 'push_type/field_type'
63
+ require 'push_type/version'
@@ -0,0 +1,3 @@
1
+ module PushType
2
+ VERSION = '0.2.1'
3
+ end
@@ -26,4 +26,23 @@ describe FrontEndController do
26
26
  end
27
27
  end
28
28
 
29
+ describe 'node filters' do
30
+ ApplicationController.module_eval do
31
+ def before_node_load
32
+ @foo = {}
33
+ end
34
+ def before_node_action
35
+ @foo[:node_action] = true
36
+ end
37
+ def before_page_action
38
+ @foo[:page_action] = true
39
+ end
40
+ end
41
+ let(:page) { FactoryGirl.create :published_node, type: 'Page' }
42
+ before { get :node, permalink: page.permalink }
43
+ it { assigns[:foo].must_be_instance_of Hash }
44
+ it { assigns[:foo][:node_action].must_equal true }
45
+ it { assigns[:foo][:page_action].must_equal true }
46
+ end
47
+
29
48
  end