Class: Rich::Cms::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/rich/cms/engine.rb

Defined Under Namespace

Classes: AuthenticationSpecs, RichCmsError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.authenticationObject (readonly)

Returns the value of attribute authentication.



11
12
13
# File 'lib/rich/cms/engine.rb', line 11

def authentication
  @authentication
end

.editable_contentObject (readonly)

Returns the value of attribute editable_content.



11
12
13
# File 'lib/rich/cms/engine.rb', line 11

def editable_content
  @editable_content
end

Class Method Details

.authenticate(logic, specs) ⇒ Object



55
56
57
# File 'lib/rich/cms/engine.rb', line 55

def authenticate(logic, specs)
  @authentication = AuthenticationSpecs.new(logic, specs)
end

.can_render_metadata?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rich/cms/engine.rb', line 77

def can_render_metadata?
  if @can_render_metadata.nil?
    @can_render_metadata = case authentication.logic
                           when :authlogic
                             @current_controller.try :current_rich_cms_admin
                           when nil
                             true
                           end
  else
    @can_render_metadata
  end
end

.copy_assetsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/rich/cms/engine.rb', line 39

def copy_assets
  return if Rails.env == "test"

  source_dir = File.join File.dirname(__FILE__), "..", "..", "..", "assets", "images", "."
  target_dir = File.join Rails.root, "public", "images", "rich", "cms"

  FileUtils.rm_r    target_dir if File.exists? target_dir
  FileUtils.mkdir_p target_dir
  FileUtils.cp_r    source_dir, target_dir
end

.current_controller=(current_controller) ⇒ Object



50
51
52
53
# File 'lib/rich/cms/engine.rb', line 50

def current_controller=(current_controller)
  @current_controller  = current_controller
  @can_render_metadata = nil
end

.editable_content_javascript_hashObject



73
74
75
# File 'lib/rich/cms/engine.rb', line 73

def editable_content_javascript_hash
  "{#{@editable_content.collect{|k, v| v.to_javascript_hash}.join ", "}}".html_safe
end

.initObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rich/cms/engine.rb', line 13

def init
  @authentication   = AuthenticationSpecs.new
  @editable_content = {}

  %w(controllers).each do |dir|
    path = File.join File.dirname(__FILE__), "..", "..", "app", dir
    $LOAD_PATH << path
    ActiveSupport::Dependencies.autoload_paths << path
    ActiveSupport::Dependencies.autoload_once_paths.delete path
  end

  procedure = proc {
    ::Jzip::Engine.add_template_location({File.expand_path("../../../../assets/jzip", __FILE__) => File.join(Rails.root, "public", "javascripts")})
    ::Sass::Plugin.add_template_location( File.expand_path("../../../../assets/sass", __FILE__),   File.join(Rails.root, "public", "stylesheets") )
    copy_assets
  }

  if Rails::VERSION::MAJOR >= 3
    config.after_initialize do
      procedure.call
    end
  else
    procedure.call
  end
end

.register(*args) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/rich/cms/engine.rb', line 59

def register(*args)
  (editables = args.first.is_a?(Hash) ? args.first : Hash[*args]).each do |selector, specs|
    if @editable_content.keys.include?(selector)
      raise RichCmsError, "Already registered editable content identified with #{selector.inspect}"
    else
      @editable_content[selector] = Cms::Content::Group.build(selector, specs)
    end
  end
end

.to_content_tag(selector, identifiers, options = {}) ⇒ Object



69
70
71
# File 'lib/rich/cms/engine.rb', line 69

def (selector, identifiers, options = {})
  editable_content[selector].fetch(identifiers).to_tag options
end