effective_pages 1.0.11 → 1.0.12

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: 630627be0f26cceb988f5660a4bf176f8ec872e2
4
- data.tar.gz: 2c21cad992101767adfd4ca8c4eeb9f304a11c78
3
+ metadata.gz: a262f391f673a4b0d27dca076bbc5cfc306547e1
4
+ data.tar.gz: 796159e1cdd9cbfea0e09a534f7bfa5a1ae97e56
5
5
  SHA512:
6
- metadata.gz: 27d32f78c747f9e58c51ec8fbb7a695a640386fc84d6e0ba04263534232e3789d806dfe379db2ce333466d9bc817867ed234db9f21464f978d71b953704dc40a
7
- data.tar.gz: 8f543b3f254c9b0b62ae8f7ff7a968424f53538c7d36e459a9426b6699de0006dec22af92ceb3440a93d876f29a25a3c185f6f05fa70736232c94c062f71e2c7
6
+ metadata.gz: 5e7bc28fd83ff3f5b923c5848d5c52cad7bc7f7dd476916b39a530e6ed1f6668536f2c81adf9d4b3c43469126bfa9dc65ea55e65f267a51c40cc0008c6669fbb
7
+ data.tar.gz: f0e511ec45b3c4cefac7087f74beae2856261a2a21eb2a32c920d6f9fbbc0a96c3b45943395405fe5125ce79a3a774bf272909a423cc260c56abd43e3d9af513
@@ -84,9 +84,7 @@ module Admin
84
84
  private
85
85
 
86
86
  def page_params
87
- params.require(:effective_page).permit(
88
- :title, :meta_description, :draft, :layout, :template, :slug, :roles => []
89
- )
87
+ params.require(:effective_page).permit(EffectivePages.permitted_params)
90
88
  end
91
89
 
92
90
  end
@@ -6,7 +6,7 @@ if defined?(EffectiveDatatables)
6
6
  table_column :id
7
7
 
8
8
  table_column :title
9
- table_column :actions, :sortable => false, :filter => false, :partial => '/admin/menus/actions'
9
+ table_column :actions, sortable: false, filter: false, partial: '/admin/menus/actions'
10
10
  end
11
11
 
12
12
  def collection
@@ -6,13 +6,13 @@ if defined?(EffectiveDatatables)
6
6
  default_order :title, :asc
7
7
  default_entries :all
8
8
 
9
- table_column :id, :visible => false
9
+ table_column :id, visible: false
10
10
 
11
11
  table_column :title
12
12
  table_column :slug
13
13
  table_column :draft
14
14
 
15
- table_column :actions, :sortable => false, :filter => false, :partial => '/admin/pages/actions'
15
+ table_column :actions, sortable: false, filter: false, partial: '/admin/pages/actions'
16
16
  end
17
17
 
18
18
  def collection
@@ -1,20 +1,22 @@
1
1
  module Effective
2
2
  class Menu < ActiveRecord::Base
3
- has_many :menu_items, :dependent => :delete_all
3
+ has_many :menu_items, dependent: :delete_all
4
4
 
5
5
  self.table_name = EffectivePages.menus_table_name.to_s
6
6
  attr_protected() if Rails::VERSION::MAJOR == 3
7
7
 
8
- structure do
9
- title :string, :validates => [:presence, :uniqueness, :length => {:maximum => 255}]
10
- timestamps
11
- end
8
+ # structure do
9
+ # title :string
10
+ # timestamps
11
+ # end
12
+
13
+ validates :title, presence: true, uniqueness: true, length: { maximum: 255 }
12
14
 
13
- accepts_nested_attributes_for :menu_items, :allow_destroy => true
15
+ accepts_nested_attributes_for :menu_items, allow_destroy: true
14
16
 
15
17
  before_save do
16
18
  if self.menu_items.find { |menu_item| menu_item.lft == 1 }.blank?
17
- menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
19
+ menu_items.build(title: 'Home', url: '/', lft: 1, rgt: 2)
18
20
  end
19
21
  end
20
22
 
@@ -36,7 +38,7 @@ module Effective
36
38
  right = attributes[:menu_items_attributes].map { |_, atts| atts[:rgt].to_i }.max
37
39
 
38
40
  root_node = menu.menu_items.find { |menu_item| menu_item.lft == 1 }
39
- root_node ||= menu.menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
41
+ root_node ||= menu.menu_items.build(title: 'Home', url: '/', lft: 1, rgt: 2)
40
42
  root_node.rgt = right + 1
41
43
 
42
44
  menu.save!
@@ -52,7 +54,7 @@ module Effective
52
54
  def build(&block)
53
55
  raise 'build must be called with a block' if !block_given?
54
56
 
55
- root = menu_items.build(:title => 'Home', :url => '/', :lft => 1, :rgt => 2)
57
+ root = menu_items.build(title: 'Home', url: '/', lft: 1, rgt: 2)
56
58
  root.parent = true
57
59
  instance_exec(&block) # A call to dropdown or item
58
60
  root.rgt = menu_items.map(&:rgt).max
@@ -2,27 +2,36 @@ module Effective
2
2
  class MenuItem < ActiveRecord::Base
3
3
  attr_accessor :parent # This gets set on the Root node and a node created by Dropdown, so the item function knows whether to go down or to go accross
4
4
 
5
- belongs_to :menu, :inverse_of => :menu_items
6
- belongs_to :menuable, :polymorphic => true # Optionaly belong to an object
5
+ belongs_to :menu, inverse_of: :menu_items
6
+ belongs_to :menuable, polymorphic: true # Optionaly belong to an object
7
7
 
8
8
  self.table_name = EffectivePages.menu_items_table_name.to_s
9
9
  attr_protected() if Rails::VERSION::MAJOR == 3
10
10
 
11
11
  acts_as_role_restricted
12
12
 
13
- structure do
14
- title :string, :validates => [:presence, :length => {:maximum => 255}]
13
+ # structure do
14
+ # title :string
15
15
 
16
- url :string, :validates => [:length => {:maximum => 255}]
17
- special :string, :validates => [:length => {:maximum => 255}] # divider / search / *_path
16
+ # url :string
17
+ # special :string # divider / search / *_path
18
18
 
19
- classes :string, :validates => [:length => {:maximum => 255}]
20
- new_window :boolean, :default => false, :validates => [:inclusion => {:in => [true, false]}]
21
- roles_mask :integer, :default => nil # 0 is going to mean logged in, -1 is going to mean public, > 0 will be future implementation of roles masking
19
+ # classes :string
20
+ # new_window :boolean
21
+ # roles_mask :integer # 0 is going to mean logged in, -1 is going to mean public, > 0 will be future implementation of roles masking
22
22
 
23
- lft :integer, :validates => [:presence], :index => true
24
- rgt :integer, :validates => [:presence]
25
- end
23
+ # lft :integer
24
+ # rgt :integer
25
+ # end
26
+
27
+ validates :title, presence: true, length: { maximum: 255 }
28
+ validates :url, length: { maximum: 255 }
29
+ validates :special, length: { maximum: 255 }
30
+ validates :classes, length: { maximum: 255 }
31
+ validates :new_window, inclusion: { in: [true, false] }
32
+
33
+ validates :lft, presence: true
34
+ validates :rgt, presence: true
26
35
 
27
36
  default_scope -> { includes(:menuable).order(:lft) }
28
37
 
@@ -42,12 +51,14 @@ module Effective
42
51
  # This will work with effective_roles one day...
43
52
  def visible_for?(user)
44
53
  can_view_page = (
45
- if menuable.kind_of?(Effective::Page)
54
+ if dropdown?
55
+ true
56
+ elsif menuable.kind_of?(Effective::Page)
46
57
  menuable.roles_permit?(user)
47
58
  else
48
59
  true
49
60
  end
50
- ) || dropdown? # If it's a dropdown, don't consider the page permissions, 'cause its not a link to the page anyway
61
+ )
51
62
 
52
63
  can_view_menu_item = (
53
64
  if roles_mask == nil
@@ -4,27 +4,36 @@ module Effective
4
4
  acts_as_role_restricted
5
5
  acts_as_regionable
6
6
 
7
- has_many :menu_items, :as => :menuable, :dependent => :destroy
7
+ if EffectivePages.acts_as_asset_box.present?
8
+ acts_as_asset_box [EffectivePages.acts_as_asset_box]
9
+ end
10
+
11
+ has_many :menu_items, as: :menuable, dependent: :destroy
8
12
 
9
13
  self.table_name = EffectivePages.pages_table_name.to_s
10
14
 
11
15
  structure do
12
- title :string, :validates => [:presence, :length => {:maximum => 255}]
13
- meta_description :string, :validates => [:presence, :length => {:maximum => 150}]
16
+ title :string
17
+ meta_description :string
14
18
 
15
- draft :boolean, :default => false
19
+ draft :boolean
16
20
 
17
- layout :string, :default => 'application', :validates => [:presence]
18
- template :string, :validates => [:presence]
21
+ layout :string
22
+ template :string
19
23
 
20
24
  slug :string
21
- roles_mask :integer, :default => 0
25
+ roles_mask :integer
22
26
 
23
27
  timestamps
24
28
  end
25
29
 
26
- scope :drafts, -> { where(:draft => true) }
27
- scope :published, -> { where(:draft => false) }
30
+ validates :title, presence: true, length: { maximum: 255 }
31
+ validates :meta_description, presence: true, length: { maximum: 150 }
32
+ validates :layout, presence: true
33
+ validates :template, presence: true
34
+
35
+ scope :drafts, -> { where(draft: true) }
36
+ scope :published, -> { where(draft: false) }
28
37
  end
29
38
 
30
39
  end
@@ -0,0 +1,2 @@
1
+ -# intentionally left blank
2
+ -# = form.input :start_at
@@ -0,0 +1,2 @@
1
+ - Effective::Page.new().asset_boxes.each do |asset_box, opts|
2
+ = form.input asset_box, as: :asset_box, required: (opts.present?), hint: "The #{asset_box.to_s.titleize.downcase} of your page."
@@ -1,25 +1,30 @@
1
- = simple_form_for(page, (EffectivePages.simple_form_options || {}).merge(:url => (page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path))) do |f|
2
- = f.input :title, :hint => "Give this page a title", :input_html => {:maxlength => 255}
3
- = f.input :draft, :hint => "Save this page as a draft. It will not be accessible on the website."
1
+ = simple_form_for(page, (EffectivePages.simple_form_options || {}).merge(url: (page.persisted? ? effective_pages.admin_page_path(page.id) : effective_pages.admin_pages_path))) do |f|
2
+ = f.input :title, hint: 'The title of your page.', input_html: { maxlength: 255 }
3
+ = f.input :draft, hint: 'Save this page as a draft. It will not be accessible on the website.'
4
4
 
5
5
  - if !f.object.new_record? || f.object.errors.include?(:slug)
6
6
  - current_url = (effective_pages.page_url(f.object) rescue nil)
7
- = f.input :slug, :hint => "The slug controls this page's internet address. Be careful, changing the slug will break links that other websites may have to the old address.<br>#{('This page is currently reachable via ' + link_to(current_url.gsub(f.object.slug, '<strong>' + f.object.slug + '</strong>').html_safe, current_url)) if current_url }".html_safe
7
+ = f.input :slug, hint: "The slug controls this page's internet address. Be careful, changing the slug will break links that other websites may have to the old address.<br>#{('This page is currently reachable via ' + link_to(current_url.gsub(f.object.slug, '<strong>' + f.object.slug + '</strong>').html_safe, current_url)) if current_url }".html_safe
8
8
 
9
- = f.input :meta_description, :hint => "A one or two sentence summary of this page. Appears on Google search results underneath the page title.", :input_html => {:maxlength => 150}
9
+ - if EffectivePages.acts_as_asset_box
10
+ = render partial: '/admin/pages/asset_box_fields', locals: { page: page, form: f, f: f }
11
+
12
+ = render partial: '/admin/pages/additional_fields', locals: { page: page, form: f, f: f }
13
+
14
+ = f.input :meta_description, hint: "A one or two sentence summary of this page. Appears on Google search results underneath the page title.", input_html: { maxlength: 150 }
10
15
 
11
16
  - if EffectivePages.pages.length == 1
12
- = f.input :template, :as => :hidden, input_html: { :value => EffectivePages.pages.first.first }
17
+ = f.input :template, as: :hidden, input_html: { value: EffectivePages.pages.first.first }
13
18
  - else
14
- = f.input :template, :as => :select, :collection => EffectivePages.pages, :include_blank => false
19
+ = f.input :template, as: (defined?(EffectiveFormInputs?) ? :effective_select : :select), collection: EffectivePages.pages, include_blank: false
15
20
 
16
21
  - if EffectivePages.layouts.length == 1
17
- = f.input :layout, :as => :hidden, :value => EffectivePages.layouts.first
22
+ = f.input :layout, as: :hidden, value: EffectivePages.layouts.first
18
23
  - else
19
- = f.input :layout, :as => :select, :collection => EffectivePages.layouts, :include_blank => false
24
+ = f.input :layout, as: (defined?(EffectiveFormInputs?) ? :effective_select : :select), collection: EffectivePages.layouts, include_blank: false
20
25
 
21
26
  - if f.object.respond_to?(:roles)
22
- = f.input :roles, :collection => EffectiveRoles.roles_collection(f.object), :as => :check_boxes, :hint => '* leave blank for a regular public page that anyone can view'
27
+ = f.input :roles, collection: EffectiveRoles.roles_collection(f.object), as: :check_boxes, hint: '* leave blank for a regular public page that anyone can view'
23
28
 
24
29
  .form-group
25
30
  .col-xs-12
@@ -11,9 +11,20 @@ module EffectivePages
11
11
  end
12
12
 
13
13
  # Set up our default configuration options.
14
- initializer "effective_pages.defaults", :before => :load_config_initializers do |app|
14
+ initializer "effective_pages.defaults", before: :load_config_initializers do |app|
15
15
  # Set up our defaults, as per our initializer template
16
16
  eval File.read("#{config.root}/lib/generators/templates/effective_pages.rb")
17
17
  end
18
+
19
+ initializer 'effective_pages.effective_assets_validation', after: :load_config_initializers do
20
+ if EffectivePages.acts_as_asset_box
21
+ begin
22
+ require 'effective_assets'
23
+ rescue Exception
24
+ raise "unable to load effective_assets. Plese add gem 'effective_assets' to your Gemfile and then 'bundle install'"
25
+ end
26
+ end
27
+ end
28
+
18
29
  end
19
30
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '1.0.11'.freeze
2
+ VERSION = '1.0.12'.freeze
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'haml-rails'
2
- require 'migrant'
3
2
  require 'effective_datatables'
4
3
  require 'effective_regions'
5
4
  require 'effective_roles'
@@ -22,6 +21,8 @@ module EffectivePages
22
21
  mattr_accessor :layout
23
22
  mattr_accessor :menu
24
23
 
24
+ mattr_accessor :acts_as_asset_box
25
+
25
26
  def self.setup
26
27
  yield self
27
28
  end
@@ -49,6 +50,10 @@ module EffectivePages
49
50
  @@pages_path = filepath.chomp('/')
50
51
  end
51
52
 
53
+ def self.permitted_params
54
+ @@permitted_params ||= [:title, :meta_description, :draft, :layout, :template, :slug, (EffectiveAssets.permitted_params if EffectivePages.acts_as_asset_box), roles: []].compact
55
+ end
56
+
52
57
  private
53
58
 
54
59
  def self.read_pages
@@ -70,7 +75,9 @@ module EffectivePages
70
75
  HashWithIndifferentAccess.new().tap do |layouts|
71
76
  files.each do |file|
72
77
  name = File.basename(file).split('.').first
73
- next if name.starts_with?('_') || Array(EffectivePages.excluded_layouts).map(&:to_s).include?(name)
78
+ next if name.starts_with?('_')
79
+ next if name.include?('mailer_layout')
80
+ next if Array(EffectivePages.excluded_layouts).map(&:to_s).include?(name)
74
81
 
75
82
  layouts[name.to_sym] = {}
76
83
  end
@@ -19,6 +19,13 @@ EffectivePages.setup do |config|
19
19
  # Any app/views/layouts/ layout files that should be excluded
20
20
  config.excluded_layouts = [:admin]
21
21
 
22
+ # Work with EffectiveAssets
23
+ # The following will be passed into the acts_as_asset_box for the Effective::Page model
24
+ # The /admin/pages/new form will create the corresponding inputs
25
+ #config.acts_as_asset_box = :header_image
26
+ #config.acts_as_asset_box = header_image: true
27
+ #config.acts_as_asset_box = { header_image: true, body_images: 1..4 }
28
+
22
29
  # Use CanCan: can?(action, resource)
23
30
  # Use effective_roles: resource.roles_permit?(current_user)
24
31
  config.authorization_method = Proc.new { |controller, action, resource| true }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: migrant
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: simple_form
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +172,8 @@ files:
186
172
  - app/views/admin/menus/index.html.haml
187
173
  - app/views/admin/menus/new.html.haml
188
174
  - app/views/admin/pages/_actions.html.haml
175
+ - app/views/admin/pages/_additional_fields.html.haml
176
+ - app/views/admin/pages/_asset_box_fields.html.haml
189
177
  - app/views/admin/pages/_form.html.haml
190
178
  - app/views/admin/pages/edit.html.haml
191
179
  - app/views/admin/pages/index.html.haml