Module: TranslationCms::InlineAsset

Defined in:
lib/translation_cms/inline_asset.rb

Class Method Summary collapse

Class Method Details

.inline_css(asset_path) ⇒ Object



29
30
31
# File 'lib/translation_cms/inline_asset.rb', line 29

def inline_css(asset_path)
  "<style type='text/css'>#{inline_file asset_path}</style>"
end

.inline_file(asset_path) ⇒ Object



18
19
20
21
22
23
# File 'lib/translation_cms/inline_asset.rb', line 18

def inline_file(asset_path)
  # file = Rails.application.assets.find_asset(asset_path)
  # file.nil? ? '' : read_file_contents(file)

  Rails.application.assets_manifest.find_sources(asset_path).first.to_s.html_safe
end

.inline_js(asset_path) ⇒ Object



25
26
27
# File 'lib/translation_cms/inline_asset.rb', line 25

def inline_js(asset_path)
  "<script type='text/javascript'>#{inline_file asset_path}</script>"
end

.read_file_contents(stylesheet) ⇒ Object



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

def read_file_contents(stylesheet)
  if %w[test development].include?(Rails.env.to_s)
    # if we're running the full asset pipeline,
    # just grab the body of the final output
    stylesheet.source
  else
    # in a production-like environment, read the
    # fingerprinted and compiled file
    File.read(File.join(Rails.root, 'public', 'assets', stylesheet.digest_path))
  end
end