Mange / roadie
Showing 57 of 66 files from the diff.
Other files ignored by Codecov
Gemfile has changed.
Changelog.md has changed.
Rakefile has changed.
roadie.gemspec has changed.
.travis.yml has changed.

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'set'
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
require 'roadie/rspec'
3 5
require 'shared_examples/asset_provider'

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
RSpec::Matchers.define :have_attribute do |attribute|
2 4
  @selector = 'body > *:first'
3 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
shared_examples_for "asset provider role" do
2 4
  it "responds to #find_stylesheet" do
3 5
    expect(subject).to respond_to(:find_stylesheet)

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  # Class that improves the markup of a HTML DOM tree

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
require 'shared_examples/url_rewriter'
4 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
require 'roadie/rspec'
3 5
require 'shared_examples/asset_provider'

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  # Domain object for a CSS property such as "color: red !important".

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  class StyleAttributeBuilder
3 5
    def initialize

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api public
3 5
  # This provider acts a bit like a pipeline in normal UNIX parlour by enabling

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require "spec_helper"
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  #

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
shared_examples_for "url rewriter" do
2 4
  it "is constructed with a generator" do
3 5
    generator = double "URL generator"
@@ -6,7 +8,7 @@
Loading
6 8
    }.to_not raise_error
7 9
  end
8 10
9 -
  it "has a #transform_dom(dom) method that returns nil" do
11 +
  it "has a #transform_dom(dom) method that returns the modified string" do
10 12
    expect(subject).to respond_to(:transform_dom)
11 13
    expect(subject.method(:transform_dom).arity).to eq(1)
12 14
@@ -14,10 +16,10 @@
Loading
14 16
    expect(subject.transform_dom(dom)).to be_nil
15 17
  end
16 18
17 -
  it "has a #transform_css(css) method that returns nil" do
19 +
  it "has a #transform_css(css) method that returns the modified string" do
18 20
    expect(subject).to respond_to(:transform_css)
19 21
    expect(subject.method(:transform_css).arity).to eq(1)
20 22
21 -
    expect(subject.transform_css("")).to be_nil
23 +
    expect(subject.transform_css("")).to eq("")
22 24
  end
23 25
end

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
require 'roadie/rspec'
3 5
require 'shared_examples/asset_provider'
@@ -18,13 +20,13 @@
Loading
18 20
      invalid_name: "http://example.com/red.css"
19 21
    ) do
20 22
      before do
21 -
        stub_request(:get, "http://example.com/green.css").and_return(body: "p { color: green; }")
23 +
        stub_request(:get, "http://example.com/green.css").and_return(body: +"p { color: green; }")
22 24
        stub_request(:get, "http://example.com/red.css").and_return(status: 404, body: "Not here!")
23 25
      end
24 26
    end
25 27
26 28
    it "can download over HTTPS" do
27 -
      stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
29 +
      stub_request(:get, "https://example.com/style.css").and_return(body: +"p { color: green; }")
28 30
      expect {
29 31
        NetHttpProvider.new.find_stylesheet!("https://example.com/style.css")
30 32
      }.to_not raise_error
@@ -37,7 +39,7 @@
Loading
37 39
      # asset inlining, but the scheme-less URL implies that there should exist
38 40
      # both a HTTP and a HTTPS endpoint. Let's take the secure one in that
39 41
      # case!
40 -
      stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
42 +
      stub_request(:get, "https://example.com/style.css").and_return(body: +"p { color: green; }")
41 43
      expect {
42 44
        NetHttpProvider.new.find_stylesheet!("//example.com/style.css")
43 45
      }.to_not raise_error
@@ -48,7 +50,7 @@
Loading
48 50
      # (US-ASCII). The headers will indicate what charset the client should
49 51
      # use when trying to make sense of these bytes.
50 52
      stub_request(:get, url).and_return(
51 -
        body: %(p::before { content: "l\xF6ve" }).force_encoding("US-ASCII"),
53 +
        body: (+%(p::before { content: "l\xF6ve" })).force_encoding("US-ASCII"),
52 54
        headers: {"Content-Type" => "text/css;charset=ISO-8859-1"},
53 55
      )
54 56
@@ -64,7 +66,7 @@
Loading
64 66
65 67
    it "assumes UTF-8 encoding if server headers do not specify a charset" do
66 68
      stub_request(:get, url).and_return(
67 -
        body: %(p::before { content: "Åh nej" }).force_encoding("US-ASCII"),
69 +
        body: (+%(p::before { content: "Åh nej" })).force_encoding("US-ASCII"),
68 70
        headers: {"Content-Type" => "text/css"},
69 71
      )
70 72
@@ -119,8 +121,8 @@
Loading
119 121
        whitelisted_url = "http://whitelisted.example.com/style.css"
120 122
        other_url       = "http://www.example.com/style.css"
121 123
122 -
        whitelisted_request = stub_request(:get, whitelisted_url).and_return(body: "x")
123 -
        other_request       = stub_request(:get, other_url).and_return(body: "x")
124 +
        whitelisted_request = stub_request(:get, whitelisted_url).and_return(body: +"x")
125 +
        other_request       = stub_request(:get, other_url).and_return(body: +"x")
124 126
125 127
        expect(provider.find_stylesheet(other_url)).to be_nil
126 128
        expect {

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
require 'shared_examples/asset_provider'
4 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'forwardable'
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api public
3 5
  # The {CachedProvider} wraps another provider (or {ProviderList}) and caches

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
3 5
describe "Roadie functionality" do

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
shared_examples_for "roadie cache store" do
2 4
  it "allows storing Stylesheets" do
3 5
    stylesheet = Roadie::Stylesheet.new("foo.css", "body { color: green; }")

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
require 'roadie/rspec'
4 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
end
3 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'forwardable'
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # Asset provider that looks for files on your local filesystem.
3 5
  #

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
shared_examples_for "roadie asset provider" do |options|
2 4
  valid_name = options[:valid_name] or raise "You must provide a :valid_name option to the shared examples"
3 5
  invalid_name = options[:invalid_name] or raise "You must provide an :invalid_name option to the shared examples"

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
require 'roadie/rspec'
3 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
RSpec::Matchers.define :have_selector do |selector|
2 4
  match { |document| !document.css(selector).empty? }
3 5
  failure_message { "expected document to have selector #{selector.inspect}"}

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
class TestProvider
2 4
  include Roadie::AssetProvider
3 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
RSpec::Matchers.define :have_xpath do |xpath|
2 4
  match { |document| !document.xpath(xpath).empty? }
3 5
  failure_message { "expected document to have xpath #{xpath.inspect}"}

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
RSpec::Matchers.define :have_node do |selector|
2 4
  chain(:with_attributes) { |attributes| @attributes = attributes }
3 5
  match do |document|

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'set'
3 4
require 'uri'
4 5
require 'net/http'

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # This module can be included in your own code to help you implement the
3 5
  # standard behavior for asset providers.

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  class Deduplicator
3 5
    def self.apply(input)

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  # Null Object for the URL rewriter role.
@@ -7,6 +9,8 @@
Loading
7 9
  class NullUrlRewriter
8 10
    def initialize(generator = nil) end
9 11
    def transform_dom(dom) end
10 -
    def transform_css(css) end
12 +
    def transform_css(css)
13 +
      css
14 +
    end
11 15
  end
12 16
end

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # Base class for all Roadie errors. Rescue this if you want to catch errors
3 5
  # from Roadie.
@@ -58,7 +60,7 @@
Loading
58 60
    # Redundant method argument is to keep API compatability without major version bump.
59 61
    # TODO: Remove argument on version 4.0.
60 62
    def build_message(extra_message = @extra_message)
61 -
      message = %(Could not find stylesheet "#{css_name}")
63 +
      message = +%(Could not find stylesheet "#{css_name}")
62 64
      message << ": #{extra_message}" if extra_message
63 65
      message << "\nUsed provider:\n#{provider}" if provider
64 66
      message
@@ -75,7 +77,7 @@
Loading
75 77
76 78
    private
77 79
    def build_message(extra_message)
78 -
      message = %(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n)
80 +
      message = +%(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n)
79 81
      each_error_row(errors) do |row|
80 82
        message << "\t" << row << "\n"
81 83
      end

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # An asset provider that returns empty stylesheets for any name.
3 5
  #

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
3 5
module Roadie

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  #
@@ -35,13 +37,12 @@
Loading
35 37
    #
36 38
    # This will make all URLs inside url() absolute.
37 39
    #
38 -
    # [nil] is returned so no one can misunderstand that this method mutates
39 -
    # the passed string.
40 +
    # Copy of CSS that is mutated is returned, passed string is not mutated.
40 41
    #
41 42
    # @param [String] css the css to mutate
42 -
    # @return [nil] css is mutated
43 +
    # @return [String] copy of css that is mutated
43 44
    def transform_css(css)
44 -
      css.gsub!(CSS_URL_REGEXP) do
45 +
      css.gsub(CSS_URL_REGEXP) do
45 46
        matches = Regexp.last_match
46 47
        "url(#{matches[:quote]}#{generate_url(matches[:url])}#{matches[:quote]})"
47 48
      end
@@ -81,8 +82,7 @@
Loading
81 82
      # We need to use a setter for Nokogiri to detect the string mutation.
82 83
      # If nokogiri used "dumber" data structures, this would all be redundant.
83 84
      css = element["style"]
84 -
      transform_css css
85 -
      element["style"] = css
85 +
      element["style"] = transform_css(css)
86 86
    end
87 87
  end
88 88
end

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # The main entry point for Roadie. A document represents a working unit and
3 5
  # is built with the input HTML and the configuration options you need.
@@ -50,7 +52,7 @@
Loading
50 52
      @html = html
51 53
      @asset_providers = ProviderList.wrap(FilesystemProvider.new)
52 54
      @external_asset_providers = ProviderList.empty
53 -
      @css = ""
55 +
      @css = +""
54 56
      @mode = :html
55 57
    end
56 58

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'spec_helper'
2 4
require 'shared_examples/url_rewriter'
3 5
@@ -71,9 +73,8 @@
Loading
71 73
      it "rewrites all url() directives" do
72 74
        expect(generator).to receive(:generate_url).with("some/path.jpg").and_return "http://foo.com/image.jpg"
73 75
        css = "body { background: top url(some/path.jpg) #eee; }"
74 -
        expect {
75 -
          rewriter.transform_css css
76 -
        }.to change { css }.to "body { background: top url(http://foo.com/image.jpg) #eee; }"
76 +
        transformed_css = rewriter.transform_css css
77 +
        expect(transformed_css).to eq "body { background: top url(http://foo.com/image.jpg) #eee; }"
77 78
      end
78 79
79 80
      it "correctly identifies URLs with single quotes" do

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require "spec_helper"
2 4
3 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'set'
2 4
require 'nokogiri'
3 5
require 'uri'

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # Domain object that represents a stylesheet (from disc, perhaps).
3 5
  #
@@ -6,7 +8,7 @@
Loading
6 8
  # @attr_reader [String] name the name of the stylesheet ("stylesheets/main.css", "Admin user styles", etc.). The name of the stylesheet will be visible if any errors occur.
7 9
  # @attr_reader [Array<StyleBlock>] blocks
8 10
  class Stylesheet
9 -
    BOM = "\xEF\xBB\xBF".force_encoding('UTF-8').freeze
11 +
    BOM = (+"\xEF\xBB\xBF").force_encoding('UTF-8').freeze
10 12
11 13
    attr_reader :name, :blocks
12 14

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
RSpec::Matchers.define :have_styling do |rules|
2 4
  normalized_rules = StylingExpectation.new(rules)
3 5

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  # @api private
3 5
  #

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
require 'roadie/rspec'
4 5
require 'shared_examples/asset_provider'

@@ -1,2 +1,4 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
require 'roadie/rspec/asset_provider'
2 4
require 'roadie/rspec/cache_store'

@@ -1,4 +1,5 @@
Loading
1 -
# encoding: UTF-8
1 +
# frozen_string_literal: true
2 +
2 3
require 'spec_helper'
3 4
4 5
module Roadie

@@ -1,3 +1,5 @@
Loading
1 +
# frozen_string_literal: true
2 +
1 3
module Roadie
2 4
  module Utils
3 5
    # @api private
Files Coverage
lib 99.17%
spec 97.28%
Project Totals (57 files) 97.97%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading