Sha256: 11a89cea6ab596ca4c7c21f940402af4b321264ae12795525f075f227e79791b

Contents?: true

Size: 569 Bytes

Versions: 1

Compression:

Stored size: 569 Bytes

Contents

class FileEditor
  def edit_urls_in_css_file(file)
    pattern = /(?<=url\(('|"))(.*?)(?=('|")\))/
    temp = Tempfile.new("fonts2.css")
    File.open(file, "r+") do |f|
      f.each { |line| temp.puts line.gsub(pattern) { |match| "/assets/imported_theme/#{asset_type(match)}/#{match.to_s.split('/').last}"}}
    end
    temp.close
    FileUtils.mv(temp.path, file)
  end

  private

  def asset_type(file_name)
    file_extension = /(?<=\w)\.\D+?\d?(?=(#|\?|$))/.match(file_name.to_s)

    (FONT_EXTENSIONS.include? file_extension.to_s) ? 'fonts' : 'images'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
theme_importer_rails-0.1.0 lib/theme_importer_rails/file_editor.rb