Module: ThemesForRails::CommonMethods

Includes:
Interpolation
Defined in:
lib/themes_for_rails/common_methods.rb

Instance Method Summary collapse

Methods included from Interpolation

#interpolate

Instance Method Details

#add_theme_view_pathObject

will add the view path for the current theme



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

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



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

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

#digest_for_image(asset, theme_context) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/themes_for_rails/common_methods.rb', line 46

def digest_for_image(asset, theme_context)
  if ThemesForRails.config.asset_digests_enabled?
    asset_paths.digest_for("#{theme_context}/images/#{asset}") || asset
  else
    asset
  end
end

#digest_for_javascript(asset, theme_context) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/themes_for_rails/common_methods.rb', line 54

def digest_for_javascript(asset, theme_context)
  if ThemesForRails.config.asset_digests_enabled?
    asset_paths.digest_for("#{theme_context}/javascripts/#{asset}") || asset
  else
    asset
  end
end

#digest_for_stylesheet(asset, theme_context) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/themes_for_rails/common_methods.rb', line 62

def digest_for_stylesheet(asset, theme_context)
  if ThemesForRails.config.asset_digests_enabled?
    #Rails.application.config.assets.digests["#{theme_context}/stylesheets/#{asset}"] || asset
    asset_paths.digest_for("#{theme_context}/stylesheets/#{asset}") || asset
  else
    asset
  end
end

#name_ext(file_name) ⇒ Object



71
72
73
74
75
76
# File 'lib/themes_for_rails/common_methods.rb', line 71

def name_ext(file_name)
  ext = File.extname(file_name)
  name = File.basename(file_name, ext)
  ext.slice!(0) if ext.length > 0
  return name, ext
end

#public_theme_pathObject



78
79
80
# File 'lib/themes_for_rails/common_methods.rb', line 78

def public_theme_path
  theme_view_path("/")
end

#set_theme(name) ⇒ Object



23
24
25
26
27
28
# File 'lib/themes_for_rails/common_methods.rb', line 23

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

#theme_asset_pathObject



82
83
84
# File 'lib/themes_for_rails/common_methods.rb', line 82

def theme_asset_path
  theme_asset_path_for(theme_name)
end

#theme_asset_path_for(theme_name) ⇒ Object



94
95
96
# File 'lib/themes_for_rails/common_methods.rb', line 94

def theme_asset_path_for(theme_name)
  interpolate(ThemesForRails.config.assets_dir, theme_name)
end

#theme_nameObject



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

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



19
20
21
# File 'lib/themes_for_rails/common_methods.rb', line 19

def theme_name=(name)
  @theme_name = name
end

#theme_view_pathObject



86
87
88
# File 'lib/themes_for_rails/common_methods.rb', line 86

def theme_view_path
  theme_view_path_for(theme_name)
end

#theme_view_path_for(theme_name) ⇒ Object



90
91
92
# File 'lib/themes_for_rails/common_methods.rb', line 90

def theme_view_path_for(theme_name)
  interpolate(ThemesForRails.config.views_dir, theme_name)
end

#valid_theme?Boolean

Returns:

  • (Boolean)


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

def valid_theme?
  !self.theme_name.nil?
end