class Roll::Amp::Style::Stylesheet

The AMP stylesheet which can be loaded from file or assets pipeline and injected into HTML body.

Public Class Methods

new(app_path, assets, stylesheet_name) click to toggle source

Initializes new instance of the AML stylesheet. @param app_path [String] the Rails application root path. @param assets [Sprockets::Environment] the Rails.application.assets @param stylesheet_name [String] the stylesheet file name.

# File lib/roll/amp/style/stylesheet.rb, line 15
def initialize(app_path, assets, stylesheet_name)
  @app_path = app_path
  @assets = assets
  @stylesheet_name = stylesheet_name
end

Public Instance Methods

read() click to toggle source

Reads stylesheet content from file or assets pipeline. Usually the pipeline is used in dev/test mode, while on production the stylesheet would be read from file. @return [String] CSS content as HTML-safe unescaped string or empty string if content couldn't be retreived.

# File lib/roll/amp/style/stylesheet.rb, line 26
def read
  raw(stylesheet_content)
end

Private Instance Methods

available_in_pipeline?() click to toggle source
# File lib/roll/amp/style/stylesheet.rb, line 40
def available_in_pipeline?
  @assets && @assets[@stylesheet_name]
end
read_from_compiled_file() click to toggle source
# File lib/roll/amp/style/stylesheet.rb, line 48
def read_from_compiled_file
  CompiledStylesheetFile.new(@app_path, @stylesheet_name).read
end
read_from_pipeline() click to toggle source
# File lib/roll/amp/style/stylesheet.rb, line 44
def read_from_pipeline
  @assets[@stylesheet_name]
end
stylesheet_content() click to toggle source
# File lib/roll/amp/style/stylesheet.rb, line 32
def stylesheet_content
  if available_in_pipeline?
    read_from_pipeline
  else
    read_from_compiled_file
  end
end