Class: Gluttonberg::Help

Inherits:
Object
  • Object
show all
Defined in:
app/models/gluttonberg/help.rb

Constant Summary collapse

@@gluttonberg_help_path =

Default help paths

"help"

Class Method Summary collapse

Class Method Details

.help_available?(opts) ⇒ Boolean

first find help in engine, if it founds return true otherwise find in application.

Returns:

  • (Boolean)


8
9
10
11
# File 'app/models/gluttonberg/help.rb', line 8

def self.help_available?(opts)
  status = help_available_in(:engine , opts)
  status ? status : help_available_in(:application , opts)
end

.help_available_in(where, opts) ⇒ Object

find help file in ‘where’. if its :application then look into application otherwise look in engine



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/gluttonberg/help.rb', line 15

def self.help_available_in(where , opts)
  if where == :application
    dir = template_dir_in_application(opts)
  else
    dir = template_dir_in_engine(opts)
  end
  
  if dir
    Dir.glob(File.join(dir ,  "/*") ).each do |template|
      return true if template.match(opts[:page].to_s)
    end
  end
  false
end

.path_to_template(opts) ⇒ Object



30
31
32
33
# File 'app/models/gluttonberg/help.rb', line 30

def self.path_to_template(opts)
  dir = template_dir(opts)
  "#{dir}/#{opts[:page]}"
end

.template_dir(opts) ⇒ Object



35
36
37
# File 'app/models/gluttonberg/help.rb', line 35

def self.template_dir(opts)        
  "#{@@gluttonberg_help_path}/#{opts[:controller]}"
end

.template_dir_in_application(opts) ⇒ Object



43
44
45
# File 'app/models/gluttonberg/help.rb', line 43

def self.template_dir_in_application(opts)
  File.join(Rails.root , "app/views" , template_dir(opts)   )
end

.template_dir_in_engine(opts) ⇒ Object



39
40
41
# File 'app/models/gluttonberg/help.rb', line 39

def self.template_dir_in_engine(opts)
  File.join(Engine.root , "app/views" , template_dir(opts)   )
end