class Cyborg::Assets::Svgs

Public Class Methods

new(plugin, path) click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 5
def initialize(plugin, path)

  require 'esvg'

  @plugin = plugin
  @base = path
  @svg = esvg
end

Public Instance Methods

build() click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 49
def build
  begin
    esvg.load_files

    return if esvg.symbols.empty?

    if files = esvg.build
      files.each do |file|
        puts build_success(file)
      end
    else
      log_error "FAILED TO BUILD SVGs"
    end
  rescue Exception => e
    log_error "\nFAILED TO BUILD SVGs"

    if e.backtrace && e.backtrace.is_a?(Array)
      log_error "Error in file: #{local_path(e.backtrace.shift)}"

      e.backtrace.each do |line|
        log_error local_path(line)
      end
    end

    log_error("  #{e.message}\n") if e.message

  end
end
build_paths() click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 45
def build_paths
  esvg.build_paths.map { |file| file.sub("-#{plugin.version}",'') }
end
esvg() click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 14
def esvg
  @svg || Esvg.new({
    config_file: File.join(plugin.root, 'config', 'esvg.yml'),
    source: @base,
    assets: plugin.paths[:javascripts],
    version: plugin.version,
    build: plugin.destination,
    temp: Cyborg.rails_path('tmp/cache/assets'),
    filename: '_icons.js',
    compress: Cyborg.production?,
    optimize: true,
    print: false
  })
end
ext() click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 29
def ext
  "svg"
end
local_path(path) click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 33
def local_path(path)
  path = File.expand_path(path)

  # Strip all irrelevant sections of the path
  path.sub(plugin.paths[:javascripts]+'/', '') # written to assets dir
      .sub(plugin.root+'/','')                 # writtent to public dir
end
use(*args) click to toggle source
# File lib/cyborg/plugin/assets/svgs.rb, line 41
def use(*args)
  esvg.use(*args)
end