class Cyborg::Assets::Stylesheets

Public Instance Methods

asset_tag(*args) click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 12
def asset_tag(*args)
  stylesheet_link_tag(args)
end
build(ext=nil) click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 16
def build(ext=nil)
  files = find_files
  files = files.reject {|f| !f.match(/\.#{ext}/) } if ext

  files.each do |file|

    begin
      if File.extname(file).match(/\.css/)
        build_css(file)
      elsif File.extname(file).match(/\.s[ca]ss/)
        build_sass(file)
      end

      puts build_success(file)

    rescue Exception => e
      build_failure file

      if e.backtrace.is_a? Array
        log_error "Error in file: #{local_path(e.backtrace[0])}"
      end

    log_error "  #{e.message}\n" if e.message
    end
  end
end
build_css(file) click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 43
def build_css(file)
  css = AutoprefixerRails.process(File.read(file)).css
  File.open(destination(file), 'w') { |io| io.write(css) }

  compress(destination(file))
end
build_sass(file) click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 50
def build_sass(file)
  style = Cyborg.production? ? "compressed" : 'nested'
  dest = destination(file)

  Sass.logger.log_level = :error if Cyborg.production?

  css = Sass.compile_file(file, style: style)
  css = AutoprefixerRails.process(css).css

  File.open(dest, 'w') { |io| io.write(css) }

  compress(dest)
end
data() click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 64
def data
  if @data
    @data
  else
    data = {}

    Dir[File.join(base, "**/*.yml")].each do |file|
      key = file.sub(base+"/", '').sub(/^_/,'').sub('.yml','')

      data[key] = SassParser.parse(file)
    end

    @data = data if Cyborg.production?
    data
  end
end
ext() click to toggle source
# File lib/cyborg/plugin/assets/stylesheets.rb, line 8
def ext
  "*[ca]ss"
end
versioned(file) click to toggle source

Convert extension

Calls superclass method Cyborg::Assets::AssetType#versioned
# File lib/cyborg/plugin/assets/stylesheets.rb, line 82
def versioned(file)
  super(file.sub(/(\.css)?\.s[ca]ss$/i,'.css'))
end