Module: EffectivePages

Defined in:
lib/effective_pages.rb,
lib/effective_pages/engine.rb,
lib/effective_pages/version.rb,
lib/generators/effective_pages/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

VERSION =
'2.0.7'.freeze

Class Method Summary collapse

Class Method Details

.authorize!(controller, action, resource) ⇒ Object



51
52
53
# File 'lib/effective_pages.rb', line 51

def self.authorize!(controller, action, resource)
  raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
end

.authorized?(controller, action, resource) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/effective_pages.rb', line 38

def self.authorized?(controller, action, resource)
  @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

  return !!authorization_method unless authorization_method.respond_to?(:call)
  controller = controller.controller if controller.respond_to?(:controller)

  begin
    !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
  rescue *@_exceptions
    false
  end
end

.layoutsObject



72
73
74
75
76
77
78
79
80
# File 'lib/effective_pages.rb', line 72

def self.layouts
  ApplicationController.view_paths.map { |path| Dir["#{path}/layouts/**"] }.flatten.reverse.map do |file|
    name = File.basename(file).split('.').first
    next if name.starts_with?('_')
    next if name.include?('mailer')
    next if Array(EffectivePages.excluded_layouts).map { |str| str.to_s }.include?(name)
    name
  end.compact
end

.pages_path=(filepath) ⇒ Object

Remove leading and trailing ‘/’ characters

Will return:  "effective/pages"


57
58
59
60
61
# File 'lib/effective_pages.rb', line 57

def self.pages_path=(filepath)
  filepath = filepath.to_s
  filepath = filepath[1..-1] if filepath.starts_with?('/')
  @@pages_path = filepath.chomp('/')
end

.permitted_paramsObject



82
83
84
# File 'lib/effective_pages.rb', line 82

def self.permitted_params
  @@permitted_params ||= [:title, :meta_description, :draft, :layout, :template, :slug, roles: []]
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



34
35
36
# File 'lib/effective_pages.rb', line 34

def self.setup
  yield self
end

.templatesObject



63
64
65
66
67
68
69
70
# File 'lib/effective_pages.rb', line 63

def self.templates
  ApplicationController.view_paths.map { |path| Dir["#{path}/#{pages_path}/**"] }.flatten.reverse.map do |file|
    name = File.basename(file).split('.').first
    next if name.starts_with?('_')
    next if Array(EffectivePages.excluded_pages).map { |str| str.to_s }.include?(name)
    name
  end.compact
end