From 57de457162d762df0f1166f430e0d19838b56e10 Mon Sep 17 00:00:00 2001 From: Sinetheta Date: Wed, 4 Nov 2015 10:26:14 -0800 Subject: [PATCH 1/2] Make convert_icon_guide_html instance method So that we can access options from within it. --- lib/fontello_rails_converter/cli.rb | 4 ++-- spec/cli_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fontello_rails_converter/cli.rb b/lib/fontello_rails_converter/cli.rb index 56b2b42..4634c79 100644 --- a/lib/fontello_rails_converter/cli.rb +++ b/lib/fontello_rails_converter/cli.rb @@ -160,12 +160,12 @@ def copy_icon_guide(zipfile, demo_file) def convert_icon_guide content = File.read(icon_guide_target_file) File.open(icon_guide_target_file, 'w') do |f| - f.write self.class.convert_icon_guide_html(content) + f.write convert_icon_guide_html(content) end puts green("Converted demo.html for asset pipeline: #{icon_guide_target_file}") end - def self.convert_icon_guide_html(content) + def convert_icon_guide_html(content) content.gsub! /css\//, "/assets/" content.gsub! "url('./font/", "url('/assets/" end diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 2db87fe..26a9535 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -7,12 +7,12 @@ }) } - describe '.convert_icon_guide_html' do + describe '#convert_icon_guide_html' do let(:content) { File.read('spec/fixtures/fontello-demo.html') } let(:converted_content) { File.read('spec/fixtures/converted/fontello-demo.html') } specify do - expect(described_class.convert_icon_guide_html(content)).to eql converted_content + expect(cli.send(:convert_icon_guide_html, content)).to eql converted_content end end From 7f8916342c86ace0e3a345fbe9bed97efcc68e56 Mon Sep 17 00:00:00 2001 From: Sinetheta Date: Wed, 4 Nov 2015 10:52:18 -0800 Subject: [PATCH 2/2] Add assets.prefix options for css and fonts Although rails assets are _generally_ in /assets they can be configured to be served from elsewhere. This breaks the demo. The reason for 2 separate options is that I use this gem in non-rails projects, where my fonts and css aren't necessarily in the same place. Since we allow users to specify the css and font asset directories separately, it makes sense that they should also be able to separate them for the purpose of serving up the demo. --- bin/fontello | 4 +++- lib/fontello_rails_converter/cli.rb | 4 ++-- spec/cli_spec.rb | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/fontello b/bin/fontello index e679a0e..b3aba21 100755 --- a/bin/fontello +++ b/bin/fontello @@ -19,7 +19,9 @@ def set_options_based_on_rails_root(options) zip_file: "#{options[:rails_root_dir]}/tmp/fontello.zip", config_file: "#{options[:asset_dir]}/fonts/config.json", fontello_session_id_file: "#{options[:rails_root_dir]}/tmp/fontello_session_id", - options_file: "#{options[:rails_root_dir]}/config/fontello_rails_converter.yml" + options_file: "#{options[:rails_root_dir]}/config/fontello_rails_converter.yml", + assets_prefix_css: "/assets", + assets_prefix_fonts: "/assets" }) end diff --git a/lib/fontello_rails_converter/cli.rb b/lib/fontello_rails_converter/cli.rb index 4634c79..cdb297f 100644 --- a/lib/fontello_rails_converter/cli.rb +++ b/lib/fontello_rails_converter/cli.rb @@ -166,8 +166,8 @@ def convert_icon_guide end def convert_icon_guide_html(content) - content.gsub! /css\//, "/assets/" - content.gsub! "url('./font/", "url('/assets/" + content.gsub! /css\//, "#{@options[:assets_prefix_css]}/" + content.gsub! "url('./font\/", "url('#{@options[:assets_prefix_fonts]}/" end def config_file_exists? diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 26a9535..65a0d96 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -1,15 +1,20 @@ require 'spec_helper' describe FontelloRailsConverter::Cli do - let(:cli) { described_class.new({ - config_file: 'spec/fixtures/fontello/config.json', - stylesheet_dir: 'vendor/assets/stylesheets' - }) + let(:options) {{ + config_file: 'spec/fixtures/fontello/config.json', + stylesheet_dir: 'vendor/assets/stylesheets' + }} + let(:cli) { described_class.new(options) } describe '#convert_icon_guide_html' do let(:content) { File.read('spec/fixtures/fontello-demo.html') } let(:converted_content) { File.read('spec/fixtures/converted/fontello-demo.html') } + let(:options){{ + assets_prefix_css: '/assets', + assets_prefix_fonts: '/assets' + }} specify do expect(cli.send(:convert_icon_guide_html, content)).to eql converted_content