Module: ThemesForRails::CommonMethods

Included in:
AssetsController
Defined in:
lib/themes_for_rails/common_methods.rb

Instance Method Summary collapse

Instance Method Details

#add_theme_view_pathObject

will add the view path for the current theme



31
32
33
# File 'lib/themes_for_rails/common_methods.rb', line 31

def add_theme_view_path
  add_theme_view_path_for(self.theme_name)
end

#add_theme_view_path_for(name) ⇒ Object

will add the view path for a given theme name



35
36
37
# File 'lib/themes_for_rails/common_methods.rb', line 35

def add_theme_view_path_for(name)
  self.view_paths.insert 0, ActionView::FileSystemResolver.new(view_path_for(name))
end

#public_theme_pathObject



38
39
40
# File 'lib/themes_for_rails/common_methods.rb', line 38

def public_theme_path
  theme_path("/")
end

#set_theme(name) ⇒ Object



20
21
22
23
24
25
# File 'lib/themes_for_rails/common_methods.rb', line 20

def set_theme(name)
  self.theme_name = name
  if valid_theme?
    add_theme_view_path
  end
end

#theme_nameObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/themes_for_rails/common_methods.rb', line 6

def theme_name
  @cached_theme_name ||= begin
    case @theme_name
    when Symbol then 
      self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s
    when String then @theme_name
    else
      nil
    end
  end
end

#theme_name=(name) ⇒ Object



17
18
19
# File 'lib/themes_for_rails/common_methods.rb', line 17

def theme_name=(name)
  @theme_name = name
end

#theme_path(base = ThemesForRails.config.base_dir) ⇒ Object



41
42
43
# File 'lib/themes_for_rails/common_methods.rb', line 41

def theme_path(base = ThemesForRails.config.base_dir)
  theme_path_for(theme_name, base)
end

#theme_path_for(name, base = ThemesForRails.config.base_dir, theme_dir = ThemesForRails.config.themes_dir) ⇒ Object



44
45
46
# File 'lib/themes_for_rails/common_methods.rb', line 44

def theme_path_for(name, base = ThemesForRails.config.base_dir, theme_dir = ThemesForRails.config.themes_dir)
  File.join(base, theme_dir, name)
end

#valid_theme?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/themes_for_rails/common_methods.rb', line 27

def valid_theme?
  !self.theme_name.nil?
end

#view_path_for(theme) ⇒ Object



3
4
5
# File 'lib/themes_for_rails/common_methods.rb', line 3

def view_path_for(theme)
  File.join(theme_path_for(theme), "views")
end