roadie 2.4.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +10 -14
  4. data/.yardopts +1 -1
  5. data/Changelog.md +38 -5
  6. data/Gemfile +3 -4
  7. data/Guardfile +12 -1
  8. data/README.md +168 -164
  9. data/Rakefile +2 -19
  10. data/lib/roadie.rb +15 -68
  11. data/lib/roadie/asset_provider.rb +7 -58
  12. data/lib/roadie/asset_scanner.rb +92 -0
  13. data/lib/roadie/document.rb +103 -0
  14. data/lib/roadie/errors.rb +57 -0
  15. data/lib/roadie/filesystem_provider.rb +30 -60
  16. data/lib/roadie/inliner.rb +72 -217
  17. data/lib/roadie/markup_improver.rb +88 -0
  18. data/lib/roadie/null_provider.rb +13 -0
  19. data/lib/roadie/null_url_rewriter.rb +12 -0
  20. data/lib/roadie/provider_list.rb +71 -0
  21. data/lib/roadie/rspec.rb +1 -0
  22. data/lib/roadie/rspec/asset_provider.rb +49 -0
  23. data/lib/roadie/selector.rb +43 -18
  24. data/lib/roadie/style_attribute_builder.rb +25 -0
  25. data/lib/roadie/style_block.rb +32 -0
  26. data/lib/roadie/style_property.rb +93 -0
  27. data/lib/roadie/stylesheet.rb +65 -0
  28. data/lib/roadie/upgrade_guide.rb +36 -0
  29. data/lib/roadie/url_generator.rb +126 -0
  30. data/lib/roadie/url_rewriter.rb +84 -0
  31. data/lib/roadie/version.rb +1 -1
  32. data/roadie.gemspec +8 -11
  33. data/spec/fixtures/big_em.css +1 -0
  34. data/spec/fixtures/stylesheets/green.css +1 -0
  35. data/spec/integration_spec.rb +125 -95
  36. data/spec/lib/roadie/asset_scanner_spec.rb +153 -0
  37. data/spec/lib/roadie/css_not_found_spec.rb +17 -0
  38. data/spec/lib/roadie/document_spec.rb +123 -0
  39. data/spec/lib/roadie/filesystem_provider_spec.rb +44 -68
  40. data/spec/lib/roadie/inliner_spec.rb +105 -537
  41. data/spec/lib/roadie/markup_improver_spec.rb +78 -0
  42. data/spec/lib/roadie/null_provider_spec.rb +21 -0
  43. data/spec/lib/roadie/null_url_rewriter_spec.rb +19 -0
  44. data/spec/lib/roadie/provider_list_spec.rb +89 -0
  45. data/spec/lib/roadie/selector_spec.rb +15 -10
  46. data/spec/lib/roadie/style_attribute_builder_spec.rb +29 -0
  47. data/spec/lib/roadie/style_block_spec.rb +35 -0
  48. data/spec/lib/roadie/style_property_spec.rb +82 -0
  49. data/spec/lib/roadie/stylesheet_spec.rb +41 -0
  50. data/spec/lib/roadie/test_provider_spec.rb +29 -0
  51. data/spec/lib/roadie/url_generator_spec.rb +121 -0
  52. data/spec/lib/roadie/url_rewriter_spec.rb +79 -0
  53. data/spec/shared_examples/asset_provider.rb +11 -0
  54. data/spec/shared_examples/url_rewriter.rb +23 -0
  55. data/spec/spec_helper.rb +6 -60
  56. data/spec/support/have_attribute_matcher.rb +2 -2
  57. data/spec/support/have_node_matcher.rb +4 -4
  58. data/spec/support/have_selector_matcher.rb +3 -3
  59. data/spec/support/have_styling_matcher.rb +51 -15
  60. data/spec/support/test_provider.rb +13 -0
  61. metadata +86 -175
  62. data/Appraisals +0 -15
  63. data/gemfiles/rails_3.0.gemfile +0 -7
  64. data/gemfiles/rails_3.0.gemfile.lock +0 -123
  65. data/gemfiles/rails_3.1.gemfile +0 -7
  66. data/gemfiles/rails_3.1.gemfile.lock +0 -126
  67. data/gemfiles/rails_3.2.gemfile +0 -7
  68. data/gemfiles/rails_3.2.gemfile.lock +0 -124
  69. data/gemfiles/rails_4.0.gemfile +0 -7
  70. data/gemfiles/rails_4.0.gemfile.lock +0 -119
  71. data/lib/roadie/action_mailer_extensions.rb +0 -95
  72. data/lib/roadie/asset_pipeline_provider.rb +0 -28
  73. data/lib/roadie/css_file_not_found.rb +0 -22
  74. data/lib/roadie/railtie.rb +0 -39
  75. data/lib/roadie/style_declaration.rb +0 -42
  76. data/spec/fixtures/app/assets/stylesheets/integration.css +0 -10
  77. data/spec/fixtures/public/stylesheets/integration.css +0 -10
  78. data/spec/fixtures/views/integration_mailer/marketing.html.erb +0 -2
  79. data/spec/fixtures/views/integration_mailer/notification.html.erb +0 -8
  80. data/spec/fixtures/views/integration_mailer/notification.text.erb +0 -6
  81. data/spec/lib/roadie/action_mailer_extensions_spec.rb +0 -227
  82. data/spec/lib/roadie/asset_pipeline_provider_spec.rb +0 -65
  83. data/spec/lib/roadie/css_file_not_found_spec.rb +0 -29
  84. data/spec/lib/roadie/style_declaration_spec.rb +0 -49
  85. data/spec/lib/roadie_spec.rb +0 -101
  86. data/spec/shared_examples/asset_provider_examples.rb +0 -11
  87. data/spec/support/anonymous_mailer.rb +0 -21
  88. data/spec/support/change_url_options.rb +0 -5
  89. data/spec/support/parse_styling.rb +0 -25
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Roadie
4
- describe CSSFileNotFound do
5
- it "is initialized with a filename" do
6
- CSSFileNotFound.new('file.css').filename.should == 'file.css'
7
- end
8
-
9
- it "can be initialized with the guess the filename was based on" do
10
- CSSFileNotFound.new('file.css', :file).guess.should == :file
11
- end
12
-
13
- it "has a nil guess when no guess was specified" do
14
- CSSFileNotFound.new('').guess.should be_nil
15
- end
16
-
17
- context "without a guess" do
18
- it "has a message with the wanted filename" do
19
- CSSFileNotFound.new('style.css').message.should == 'Could not find style.css'
20
- end
21
- end
22
-
23
- context "with a guess" do
24
- it "has a message with the wanted filename and the guess" do
25
- CSSFileNotFound.new('style.css', :style).message.should == 'Could not find style.css (guessed from :style)'
26
- end
27
- end
28
- end
29
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Roadie
4
- describe StyleDeclaration do
5
- it "is initialized with a property, value, if it is marked as important, and the specificity" do
6
- StyleDeclaration.new('color', 'green', true, 45).tap do |declaration|
7
- declaration.property.should == 'color'
8
- declaration.value.should == 'green'
9
- declaration.should be_important
10
- declaration.specificity.should == 45
11
- end
12
- end
13
-
14
- describe "string representation" do
15
- it "is the property and the value joined with a colon" do
16
- StyleDeclaration.new('color', 'green', false, 1).to_s.should == 'color:green'
17
- StyleDeclaration.new('font-size', '1.1em', false, 1).to_s.should == 'font-size:1.1em'
18
- end
19
-
20
- it "contains the !important flag when set" do
21
- StyleDeclaration.new('color', 'green', true, 1).to_s.should == 'color:green !important'
22
- end
23
- end
24
-
25
- describe "comparing" do
26
- def declaration(specificity, important = false)
27
- StyleDeclaration.new('color', 'green', important, specificity)
28
- end
29
-
30
- it "compares on specificity" do
31
- declaration(5).should be == declaration(5)
32
- declaration(4).should be < declaration(5)
33
- declaration(6).should be > declaration(5)
34
- end
35
-
36
- context "with an important declaration" do
37
- it "is less than the important declaration regardless of the specificity" do
38
- declaration(99, false).should be < declaration(1, true)
39
- end
40
-
41
- it "compares like normal when both declarations are important" do
42
- declaration(5, true).should be == declaration(5, true)
43
- declaration(4, true).should be < declaration(5, true)
44
- declaration(6, true).should be > declaration(5, true)
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Roadie do
4
- let(:config) { Rails.application.config }
5
-
6
- describe ".inline_css" do
7
- it "creates an instance of Roadie::Inliner and execute it" do
8
- Roadie::Inliner.should_receive(:new).with('attri', 'butes').and_return(double('inliner', :execute => 'html'))
9
- Roadie.inline_css('attri', 'butes').should == 'html'
10
- end
11
- end
12
-
13
- describe ".app" do
14
- it "delegates to Rails.application" do
15
- Rails.stub(:application => 'application')
16
- Roadie.app.should == 'application'
17
- end
18
- end
19
-
20
- describe ".providers" do
21
- it "returns an array of all provider classes" do
22
- Roadie.should have(2).providers
23
- Roadie.providers.should include(Roadie::AssetPipelineProvider, Roadie::FilesystemProvider)
24
- end
25
- end
26
-
27
- describe ".enabled?" do
28
- it "returns the value of config.roadie.enabled" do
29
- config.roadie.stub :enabled => true
30
- Roadie.should be_enabled
31
- config.roadie.stub :enabled => false
32
- Roadie.should_not be_enabled
33
- end
34
- end
35
-
36
- describe ".current_provider" do
37
- let(:provider) { double("provider instance") }
38
-
39
- context "with a set provider in the config" do
40
- it "uses the set provider" do
41
- config.roadie.provider = provider
42
- Roadie.current_provider.should == provider
43
- end
44
- end
45
-
46
- context "when Rails' asset pipeline is not present" do
47
- before(:each) do
48
- # Turns out it's pretty much impossible to work with Rails.application.config
49
- # in a nice way; it changed quite a lot since 3.0. There's also no way of
50
- # removing a configuration key after it's set, we cannot remove the assets
51
- # config completely to trigger the normal error triggered in a 3.0 app (NoMethodError)
52
- # We'll simulate it by mutating it in an ugly way for this test
53
- config.stub(:assets).and_raise(NoMethodError)
54
- config.stub(:respond_to?).with(:assets) { false }
55
- end
56
-
57
- it "uses the FilesystemProvider" do
58
- Roadie::FilesystemProvider.should_receive(:new).and_return(provider)
59
- Roadie.current_provider.should == provider
60
- end
61
- end
62
-
63
- context "with rails' asset pipeline enabled" do
64
- before(:each) { config.assets.enabled = true }
65
-
66
- it "uses the AssetPipelineProvider" do
67
- Roadie::AssetPipelineProvider.should_receive(:new).and_return(provider)
68
- Roadie.current_provider.should == provider
69
- end
70
- end
71
-
72
- context "with rails 4.0's asset pipeline enabled" do
73
- before(:each) { config.assets.enabled = nil }
74
-
75
- it "uses the AssetPipelineProvider" do
76
- Roadie::AssetPipelineProvider.should_receive(:new).and_return(provider)
77
- Roadie.current_provider.should == provider
78
- end
79
- end
80
-
81
- context "with rails' asset pipeline disabled" do
82
- before(:each) { config.assets.enabled = false }
83
-
84
- it "uses the FilesystemProvider" do
85
- Roadie::FilesystemProvider.should_receive(:new).and_return(provider)
86
- Roadie.current_provider.should == provider
87
- end
88
- end
89
- end
90
-
91
- describe ".after_inlining_handler" do
92
- let(:after_inlining_handler) { double("after inlining handler") }
93
-
94
- it "returns the value of config.roadie.after_inlining_handler" do
95
- config.roadie.after_inlining = after_inlining_handler
96
- Roadie.after_inlining_handler.should == after_inlining_handler
97
- config.roadie.after_inlining = nil
98
- Roadie.after_inlining_handler.should == nil
99
- end
100
- end
101
- end
@@ -1,11 +0,0 @@
1
- shared_examples_for Roadie::AssetProvider do
2
- describe "#all(files)" do
3
- it "loads files in order and join them with a newline" do
4
- provider.should_receive(:find).with('one').twice.and_return('contents of one')
5
- provider.should_receive(:find).with('two').twice.and_return('contents of two')
6
-
7
- provider.all(%w[one two]).should == "contents of one\ncontents of two"
8
- provider.all(%w[two one]).should == "contents of two\ncontents of one"
9
- end
10
- end
11
- end
@@ -1,21 +0,0 @@
1
- # Subclass of ActionMailer::Base that does not crash when the class
2
- # is anonymous. Subclassed in the specs whenever a new mailer is
3
- # needed
4
- class AnonymousMailer < ActionMailer::Base
5
- class << self
6
- # Pretty much like super, but returns "anonymous" when no
7
- # name is set
8
- def mailer_name
9
- if @mailer_name or name
10
- super
11
- else
12
- "anonymous"
13
- end
14
- end
15
-
16
- # Was an alias. (e.g. pointed to the old, non-overridden method)
17
- def controller_path
18
- mailer_name
19
- end
20
- end
21
- end
@@ -1,5 +0,0 @@
1
- # ActionMailer::Base loads the default_url_options on startup via its Railtie
2
- def change_default_url_options(new_options)
3
- Rails.application.config.action_mailer.default_url_options = new_options
4
- ActionMailer::Base.default_url_options = new_options
5
- end
@@ -1,25 +0,0 @@
1
- module SpecHelpers
2
- class << self
3
- def styling_of_node(node)
4
- if node and node['style'].present?
5
- parse_styling(node['style'])
6
- else
7
- []
8
- end
9
- end
10
-
11
- def parse_styling(styles)
12
- styles.split(';').map { |style| parse_style(style) }
13
- end
14
-
15
- private
16
- def parse_style(style)
17
- rule, value = style.split(':', 2).map(&:strip)
18
- [rule, normalize_escaped_quotes(value)]
19
- end
20
-
21
- def normalize_escaped_quotes(string)
22
- string.gsub('%22', '"')
23
- end
24
- end
25
- end