Class: Revelry::Content::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/revelry/content/configuration.rb

Instance Method Summary collapse

Instance Method Details

#authorization_policy(&block) ⇒ Object



26
27
28
29
30
31
# File 'lib/revelry/content/configuration.rb', line 26

def authorization_policy(&block)
  if block_given?
    @authorization_policy = block
  end
  @authorization_policy || default_authorization_policy
end

#authorize(controller) ⇒ Object



46
47
48
49
# File 'lib/revelry/content/configuration.rb', line 46

def authorize(controller)
  user = user_for_content.call(controller)
  authorization_policy.call(user)
end

#default_authorization_policyObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/revelry/content/configuration.rb', line 33

def default_authorization_policy
  ->(user) do
    if user.present?
      if user.respond_to?(:has_role?)
        return user.has_role? :admin
      else
        return user.admin?
      end
    end
    false
  end
end

#default_markdown_rendererObject



59
60
61
# File 'lib/revelry/content/configuration.rb', line 59

def default_markdown_renderer
  Redcarpet::Render::HTML
end

#default_sanitizerObject



71
72
73
# File 'lib/revelry/content/configuration.rb', line 71

def default_sanitizer
  ->(rendered_content) { Sanitize.fragment(rendered_content, Sanitize::Config::BASIC.merge(remove_contents: true)) }
end

#default_user_finderObject



22
23
24
# File 'lib/revelry/content/configuration.rb', line 22

def default_user_finder
  ->(controller) { controller.current_user }
end

#js_exportObject



2
3
4
# File 'lib/revelry/content/configuration.rb', line 2

def js_export
  @js_export || false
end

#js_export=(v) ⇒ Object



10
11
12
# File 'lib/revelry/content/configuration.rb', line 10

def js_export=(v)
  @js_export = v
end

#js_export?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/revelry/content/configuration.rb', line 6

def js_export?
  js_export
end

#markdown_rendererObject



51
52
53
# File 'lib/revelry/content/configuration.rb', line 51

def markdown_renderer
  @markdown_renderer || default_markdown_renderer
end

#markdown_renderer=(klass) ⇒ Object



55
56
57
# File 'lib/revelry/content/configuration.rb', line 55

def markdown_renderer=(klass)
  @markdown_renderer = klass
end

#sanitizerObject



67
68
69
# File 'lib/revelry/content/configuration.rb', line 67

def sanitizer
  @sanitizer || default_sanitizer
end

#sanitizer=(klass) ⇒ Object



63
64
65
# File 'lib/revelry/content/configuration.rb', line 63

def sanitizer=(klass)
  @sanitizer = klass
end

#user_for_content(&block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/revelry/content/configuration.rb', line 14

def user_for_content(&block)
  if block_given?
    @user_finder = block
  end

  @user_finder || default_user_finder
end