Sha256: 1801c1aef822e6380c45a53438cb9afe61f072a3e21862d8d3f632f80d2be016

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

class RevelryContent::Configuration
  def js_export
    @js_export || false
  end

  def js_export?
    js_export
  end

  def js_export=(v)
    @js_export = v
  end

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

    @user_finder || default_user_finder
  end

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

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

  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

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

  def markdown_renderer
    @markdown_renderer || default_markdown_renderer
  end

  def markdown_renderer=(klass)
    @markdown_renderer = klass
  end

  def default_markdown_renderer
    Redcarpet::Render::HTML
  end

  def sanitizer=(klass)
    @sanitizer = klass
  end

  def sanitizer
    @sanitizer || default_sanitizer
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
revelry_content-0.0.1.2 lib/revelry_content/configuration.rb
revelry_content-0.0.1.1 lib/revelry_content/configuration.rb