Module: CmsUtils

Defined in:
lib/padrino-cms/lib/cms_utils.rb,
lib/padrino-cms/generators/templates/lib/cms_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cmsify(contents, opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/padrino-cms/lib/cms_utils.rb', line 7

def self.cmsify(contents, opts)
  opts[:path] ||= "/"
  opts[:field] ||= "body"
  value = (contents.empty? or contents.first.nil?) ? '' : contents.first.send(opts[:field])
  #
  # logger.debug "@current_account : #{@current_account}, role : #{@current_account.role}, contents : #{contents}"
  if @current_account and @current_account.role == "admin"
    if contents.empty? or contents.first.nil?
      label = "add #{opts[:field]}"
      url = "/admin/contents/new?path=#{opts[:path]}"
    else
      label = 'edit'
      url = "/admin/contents/edit/#{contents.first.to_param}"
    end
    value += %Q(<a href="#{url}" class="cmsified" title="#{label}"><img src="/admin/images/edit.png" alt="#{label}"/></a>)
  end
  value
end

.current_account(session_id) ⇒ Object



47
48
49
# File 'lib/padrino-cms/lib/cms_utils.rb', line 47

def self. session_id
  @current_account = Account.find_by_id(session_id) if defined?(Account)
end

.default_path(request) ⇒ Object

Returns the default key for the current request, this will be request.route.path if present otherwise request.path



33
34
35
36
37
38
39
40
41
# File 'lib/padrino-cms/lib/cms_utils.rb', line 33

def self.default_path request
  raise "Unable to access current request." if request.nil?

  if request.respond_to? 'route' and request.route.is_a? HttpRouter::Route
    request.route.path
  else
    request.path_info
  end
end

Instance Method Details

#cmsify(contents = @contents, opts = {}) ⇒ Object



3
4
5
# File 'lib/padrino-cms/lib/cms_utils.rb', line 3

def cmsify contents=@contents, opts={}
  self.class.cmsify contents, opts
end

#current_account(session_id) ⇒ Object



43
44
45
# File 'lib/padrino-cms/lib/cms_utils.rb', line 43

def  session_id
  self.class  session_id
end

#default_path(request) ⇒ Object



26
27
28
# File 'lib/padrino-cms/lib/cms_utils.rb', line 26

def default_path request
  self.class.default_path request
end