Module: ThemesForRails

Defined in:
lib/themes_for_rails.rb,
lib/themes_for_rails/config.rb,
lib/themes_for_rails/routes.rb,
lib/themes_for_rails/railtie.rb,
lib/themes_for_rails/version.rb,
lib/themes_for_rails/action_view.rb,
lib/themes_for_rails/url_helpers.rb,
lib/themes_for_rails/action_mailer.rb,
lib/themes_for_rails/interpolation.rb,
lib/themes_for_rails/common_methods.rb,
lib/themes_for_rails/action_controller.rb,
lib/themes_for_rails/assets_controller.rb,
lib/themes_for_rails/digested_action_view.rb,
lib/generators/themes_for_rails/theme_generator.rb,
lib/generators/themes_for_rails/install_generator.rb

Defined Under Namespace

Modules: ActionController, ActionMailer, ActionView, CommonMethods, DigestedActionView, Generators, Interpolation, Routes, UrlHelpers Classes: AssetsController, Config, Railtie

Constant Summary collapse

VERSION =
"1.5.1"

Class Method Summary collapse

Class Method Details

.add_themes_assets_to_asset_pipelineObject



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

def add_themes_assets_to_asset_pipeline
  Rails.logger.info "Start adding themes to assets [#{ThemesForRails.config.asset_digests_enabled?}]"
  if ThemesForRails.config.asset_digests_enabled?
    available_theme_names.each do |theme_name|
      theme_asset_path = ThemesForRails.config.assets_dir.gsub(":root", ThemesForRails.config.base_dir).gsub(":name", theme_name.to_s)
      Rails.logger.info "== Adding theme [#{theme_name}] asset dir [#{theme_asset_path}] to asset pipeline"
      Rails.application.config.assets.paths.prepend(theme_asset_path) unless Rails.application.config.assets.paths.include?(theme_asset_path)
    end unless ThemesForRails.config.base_dir =~ %r!/app/assets/!
  end
end

.add_themes_path_to_sassObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/themes_for_rails.rb', line 21

def add_themes_path_to_sass
  if ThemesForRails.config.sass_is_available?
    each_theme_dir do |dir|
      if File.directory?(dir) # Need to get rid of the '.' and '..'

        sass_dir = "#{dir}/stylesheets/sass"
        css_dir = "#{dir}/stylesheets"

        unless already_configured_in_sass?(sass_dir)
          Sass::Plugin.add_template_location sass_dir, css_dir 
        end
      end
    end 
  else
    raise "Sass is not available. What are you trying to do?"
  end
end

.already_configured_in_sass?(sass_dir) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/themes_for_rails.rb', line 54

def already_configured_in_sass?(sass_dir)
  Sass::Plugin.template_location_array.map(&:first).include?(sass_dir)
end

.available_theme_namesObject



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

def available_theme_names
  available_themes.map {|theme| File.basename(theme) } 
end

.available_themes(&block) ⇒ Object Also known as: each_theme_dir



12
13
14
# File 'lib/themes_for_rails.rb', line 12

def available_themes(&block)
  Dir.glob(File.join(config.themes_path, "*"), &block) 
end

.check_asset_pipelineObject



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

def check_asset_pipeline
  config.asset_digests_enabled ||= Rails.application.config.respond_to?(:assets) && Rails.application.config.assets.digest == true
end

.config {|@config| ... } ⇒ Object

Yields:



6
7
8
9
10
# File 'lib/themes_for_rails.rb', line 6

def config
  @config ||= ThemesForRails::Config.new
  yield(@config) if block_given?
  @config
end