montage 0.2.1
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.
- data/.document +5 -0
- data/.gitignore +31 -0
- data/History.md +40 -0
- data/LICENSE +19 -0
- data/README.md +89 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/montage +22 -0
- data/lib/montage.rb +33 -0
- data/lib/montage/commands.rb +32 -0
- data/lib/montage/commands/generate.rb +234 -0
- data/lib/montage/commands/init.rb +119 -0
- data/lib/montage/core_ext.rb +80 -0
- data/lib/montage/project.rb +185 -0
- data/lib/montage/sass_builder.rb +37 -0
- data/lib/montage/source.rb +75 -0
- data/lib/montage/sprite.rb +132 -0
- data/lib/montage/templates/montage.yml +26 -0
- data/lib/montage/templates/sass_mixins.erb +20 -0
- data/lib/montage/templates/sources/book.png +0 -0
- data/lib/montage/templates/sources/box-label.png +0 -0
- data/lib/montage/templates/sources/calculator.png +0 -0
- data/lib/montage/templates/sources/calendar-month.png +0 -0
- data/lib/montage/templates/sources/camera.png +0 -0
- data/lib/montage/templates/sources/eraser.png +0 -0
- data/lib/montage/version.rb +3 -0
- data/montage.gemspec +145 -0
- data/spec/fixtures/custom_dirs/montage.yml +8 -0
- data/spec/fixtures/default/montage.yml +7 -0
- data/spec/fixtures/default/public/images/sprites/src/one.png +0 -0
- data/spec/fixtures/default/public/images/sprites/src/three.png +0 -0
- data/spec/fixtures/default/public/images/sprites/src/two.png +0 -0
- data/spec/fixtures/directory_config/config/montage.yml +5 -0
- data/spec/fixtures/missing_source/montage.yml +3 -0
- data/spec/fixtures/missing_source_dir/montage.yml +5 -0
- data/spec/fixtures/root_config/montage.yml +5 -0
- data/spec/fixtures/root_config/public/images/sprites/src/source_one.png +0 -0
- data/spec/fixtures/root_config/public/images/sprites/src/source_three.jpg +0 -0
- data/spec/fixtures/root_config/public/images/sprites/src/source_two +0 -0
- data/spec/fixtures/sources/hundred.png +0 -0
- data/spec/fixtures/sources/mammoth.png +0 -0
- data/spec/fixtures/sources/other.png +0 -0
- data/spec/fixtures/sources/twenty.png +0 -0
- data/spec/fixtures/subdirs/montage.yml +5 -0
- data/spec/fixtures/subdirs/sub/sub/keep +0 -0
- data/spec/lib/command_runner.rb +140 -0
- data/spec/lib/fixtures.rb +7 -0
- data/spec/lib/have_public_method_defined.rb +19 -0
- data/spec/lib/project_helper.rb +135 -0
- data/spec/lib/shared_project_specs.rb +32 -0
- data/spec/lib/shared_sprite_specs.rb +30 -0
- data/spec/montage/commands/generate_spec.rb +308 -0
- data/spec/montage/commands/init_spec.rb +120 -0
- data/spec/montage/core_ext_spec.rb +33 -0
- data/spec/montage/project_spec.rb +181 -0
- data/spec/montage/sass_builder_spec.rb +269 -0
- data/spec/montage/source_spec.rb +53 -0
- data/spec/montage/spec/have_public_method_defined_spec.rb +31 -0
- data/spec/montage/sprite_spec.rb +170 -0
- data/spec/rcov.opts +8 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +19 -0
- data/tasks/spec.rake +17 -0
- data/tasks/yard.rake +11 -0
- metadata +249 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
# ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
context 'Generating a new project in the current directory' do
|
6
|
+
before(:all) do
|
7
|
+
@runner = Montage::Spec::InitCommandRunner.new.run!
|
8
|
+
end
|
9
|
+
|
10
|
+
it { @runner.should be_success }
|
11
|
+
it { @runner.stdout.should =~ /Your project was created/ }
|
12
|
+
it { @runner.path_to_file('montage.yml').should be_file }
|
13
|
+
|
14
|
+
# Example sources?
|
15
|
+
|
16
|
+
it 'should copy the sample source images' do
|
17
|
+
%w( book box-label calculator calendar-month camera eraser ).each do |source|
|
18
|
+
(@runner.project.paths.sources + "#{source}.png").should be_file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Config
|
23
|
+
|
24
|
+
describe 'the montage.yml file' do
|
25
|
+
before(:all) do
|
26
|
+
@config = File.read(@runner.project.paths.config)
|
27
|
+
end
|
28
|
+
|
29
|
+
it { @config.should =~ %r{^ config.sprites:\s+"public/images/sprites"$} }
|
30
|
+
it { @config.should =~ %r{^ config.sources:\s+"public/images/sprites/src"$} }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# ----------------------------------------------------------------------------
|
35
|
+
|
36
|
+
context 'Generating a new project in a path which has a ./config directory' do
|
37
|
+
before(:all) do
|
38
|
+
@runner = Montage::Spec::InitCommandRunner.new
|
39
|
+
@runner.mkdir('config')
|
40
|
+
@runner.run!
|
41
|
+
end
|
42
|
+
|
43
|
+
it { @runner.should be_success }
|
44
|
+
it { @runner.stdout.should =~ /Your project was created/ }
|
45
|
+
it { @runner.path_to_file('config/montage.yml').should be_file }
|
46
|
+
it { @runner.path_to_file('montage.yml').should_not be_file }
|
47
|
+
end
|
48
|
+
|
49
|
+
# ----------------------------------------------------------------------------
|
50
|
+
|
51
|
+
context 'Generating a new project in an existing project directory' do
|
52
|
+
before(:all) do
|
53
|
+
@runner = Montage::Spec::InitCommandRunner.new
|
54
|
+
2.times { @runner.run! }
|
55
|
+
end
|
56
|
+
|
57
|
+
it { @runner.should be_failure }
|
58
|
+
it { @runner.stdout.should =~ /A Montage project already exists in the current directory/ }
|
59
|
+
end
|
60
|
+
|
61
|
+
# ----------------------------------------------------------------------------
|
62
|
+
|
63
|
+
context 'Generating a new project in an existing project which has a ./config directory' do
|
64
|
+
before(:all) do
|
65
|
+
@runner = Montage::Spec::InitCommandRunner.new
|
66
|
+
@runner.mkdir('config')
|
67
|
+
2.times { @runner.run! }
|
68
|
+
end
|
69
|
+
|
70
|
+
it { @runner.should be_failure }
|
71
|
+
it { @runner.stdout.should =~ /A Montage project already exists in the current directory/ }
|
72
|
+
end
|
73
|
+
|
74
|
+
# ----------------------------------------------------------------------------
|
75
|
+
|
76
|
+
context 'Generating a new project with a custom sprites directory' do
|
77
|
+
describe 'the montage.yml file' do
|
78
|
+
before(:all) do
|
79
|
+
@runner = Montage::Spec::InitCommandRunner.new(
|
80
|
+
:sprites => 'public/other').run!
|
81
|
+
|
82
|
+
@config = File.read(@runner.project.paths.config)
|
83
|
+
end
|
84
|
+
|
85
|
+
it { @config.should =~ %r{^ config.sprites:\s+"public/other"$} }
|
86
|
+
it { @config.should =~ %r{^ config.sources:\s+"public/other/src"$} }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# ----------------------------------------------------------------------------
|
91
|
+
|
92
|
+
context 'Generating a new project with an absolute custom sprites directory' do
|
93
|
+
describe 'the montage.yml file' do
|
94
|
+
before(:all) do
|
95
|
+
@runner = Montage::Spec::InitCommandRunner.new(
|
96
|
+
:sprites => '/tmp').run!
|
97
|
+
|
98
|
+
@config = File.read(@runner.project.paths.config)
|
99
|
+
end
|
100
|
+
|
101
|
+
it { @config.should =~ %r{^ config.sprites:\s+"/tmp"$} }
|
102
|
+
it { @config.should =~ %r{^ config.sources:\s+"/tmp/src"$} }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# ----------------------------------------------------------------------------
|
107
|
+
|
108
|
+
context 'Generating a new project with a custom sprites and sources directory' do
|
109
|
+
describe 'the montage.yml file' do
|
110
|
+
before(:all) do
|
111
|
+
@runner = Montage::Spec::InitCommandRunner.new(
|
112
|
+
:sprites => 'public/other', :sources => 'src/sprites').run!
|
113
|
+
|
114
|
+
@config = File.read(@runner.project.paths.config)
|
115
|
+
end
|
116
|
+
|
117
|
+
it { @config.should =~ %r{^ config.sprites:\s+"public/other"$} }
|
118
|
+
it { @config.should =~ %r{^ config.sources:\s+"src/sprites"$} }
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
it 'should not do anything when there is no leading whitespace' do
|
5
|
+
"abc\ndef\nhij".unindent.should == "abc\ndef\nhij"
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should remove leading whitespace consistently' do
|
9
|
+
" abc\n def\n hij".unindent.should == "abc\ndef\nhij"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should remove no whitespace when one line has none' do
|
13
|
+
" abc\ndef\n hij".unindent.should == " abc\ndef\n hij"
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should ignore blank lines' do
|
17
|
+
" abc\n def\n\n hij".unindent.should == "abc\ndef\n\nhij"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should remove no more whitespace than required' do
|
21
|
+
# Left-most at beginning.
|
22
|
+
unindented = " abc\n def\n hij\n lmn".unindent
|
23
|
+
unindented.should == "abc\n def\n hij\n lmn"
|
24
|
+
|
25
|
+
# Left-most in middle.
|
26
|
+
unindented = " abc\n def\n hij\n lmn".unindent
|
27
|
+
unindented.should == " abc\n def\nhij\n lmn"
|
28
|
+
|
29
|
+
# Left-most at end.
|
30
|
+
unindented = " abc\n def\n hij\n lmn".unindent
|
31
|
+
unindented.should == " abc\n def\n hij\nlmn"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Montage::Project do
|
4
|
+
subject { Montage::Project }
|
5
|
+
|
6
|
+
# Class Methods ============================================================
|
7
|
+
|
8
|
+
# --- find -----------------------------------------------------------------
|
9
|
+
|
10
|
+
it { should respond_to(:find) }
|
11
|
+
|
12
|
+
describe '.find' do
|
13
|
+
describe 'when given a project root with montage.yml in the root' do
|
14
|
+
before(:all) do
|
15
|
+
@project = Montage::Project.find(fixture_path(:root_config))
|
16
|
+
@root = Pathname.new(fixture_path(:root_config))
|
17
|
+
@config = Pathname.new(fixture_path(:root_config, 'montage.yml'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like 'a project with correct paths'
|
21
|
+
end # when given a project root with montage.yml in the root
|
22
|
+
|
23
|
+
describe 'when given a project root with montage.yml in ./config' do
|
24
|
+
before(:all) do
|
25
|
+
@project = Montage::Project.find(fixture_path(:directory_config))
|
26
|
+
@root = Pathname.new(fixture_path(:directory_config))
|
27
|
+
@config = Pathname.new(
|
28
|
+
fixture_path(:directory_config, 'config/montage.yml'))
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like 'a project with correct paths'
|
32
|
+
end # when given a project root with montage.yml in ./config
|
33
|
+
|
34
|
+
describe 'when given a project subdirectory' do
|
35
|
+
before(:all) do
|
36
|
+
@project = Montage::Project.find(fixture_path(:subdirs, 'sub/sub'))
|
37
|
+
@root = Pathname.new(fixture_path(:subdirs))
|
38
|
+
@config = Pathname.new(fixture_path(:subdirs, 'montage.yml'))
|
39
|
+
end
|
40
|
+
|
41
|
+
it_should_behave_like 'a project with correct paths'
|
42
|
+
end # when given a project subdirectory
|
43
|
+
|
44
|
+
describe 'when given a configuration file in the root' do
|
45
|
+
before(:all) do
|
46
|
+
@project = Montage::Project.find(
|
47
|
+
fixture_path(:root_config, 'montage.yml'))
|
48
|
+
|
49
|
+
@root = Pathname.new(fixture_path(:root_config))
|
50
|
+
@config = Pathname.new(fixture_path(:root_config, 'montage.yml'))
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like 'a project with correct paths'
|
54
|
+
end # when given a configuration file in the root
|
55
|
+
|
56
|
+
describe 'when given a configuration file in ./config' do
|
57
|
+
before(:all) do
|
58
|
+
@project = Montage::Project.find(
|
59
|
+
fixture_path(:directory_config, 'config/montage.yml'))
|
60
|
+
@root = Pathname.new(fixture_path(:directory_config))
|
61
|
+
@config = Pathname.new(
|
62
|
+
fixture_path(:directory_config, 'config/montage.yml'))
|
63
|
+
end
|
64
|
+
|
65
|
+
it_should_behave_like 'a project with correct paths'
|
66
|
+
end # when given a configuration file in ./config
|
67
|
+
|
68
|
+
describe 'when the config file specifies custom directories' do
|
69
|
+
before(:all) do
|
70
|
+
@project = Montage::Project.find(fixture_path(:custom_dirs))
|
71
|
+
@base = Pathname.new(fixture_path(:custom_dirs)) + 'custom'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should set the sources path' do
|
75
|
+
@project.paths.sources.should == @base + 'sources'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should set the sprites path' do
|
79
|
+
@project.paths.sprites.should == @base + 'output'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should set the SASS output path' do
|
83
|
+
@project.paths.sass.should == @base + 'sass'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'when the config file specifies not to generate Sass' do
|
88
|
+
before(:all) do
|
89
|
+
@helper = Montage::Spec::ProjectHelper.new
|
90
|
+
@helper.write_config <<-CONFIG
|
91
|
+
---
|
92
|
+
config.sass: false
|
93
|
+
CONFIG
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should set the SASS output path to false' do
|
97
|
+
@helper.project.paths.sass.should be_false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'when given an empty directory' do
|
102
|
+
it 'should raise an error' do
|
103
|
+
running = lambda { Montage::Project.find(fixture_path(:empty)) }
|
104
|
+
running.should raise_exception(Montage::MissingProject)
|
105
|
+
end
|
106
|
+
end # when given an empty directory
|
107
|
+
|
108
|
+
describe 'when given an invalid path' do
|
109
|
+
it 'should raise an error' do
|
110
|
+
running = lambda { Montage::Project.find('__invalid__') }
|
111
|
+
running.should raise_exception(Montage::MissingProject)
|
112
|
+
end
|
113
|
+
end # when given an invalid path
|
114
|
+
end
|
115
|
+
|
116
|
+
# Instance Methods =========================================================
|
117
|
+
|
118
|
+
it { should have_public_method_defined(:paths) }
|
119
|
+
|
120
|
+
# --- sprites --------------------------------------------------------------
|
121
|
+
|
122
|
+
it { should have_public_method_defined(:sprites) }
|
123
|
+
|
124
|
+
describe '#sprites' do
|
125
|
+
context "when the project has one sprite with two sources" do
|
126
|
+
before(:each) do
|
127
|
+
@helper = Montage::Spec::ProjectHelper.new
|
128
|
+
@helper.write_config <<-CONFIG
|
129
|
+
---
|
130
|
+
sprite_one:
|
131
|
+
- one
|
132
|
+
- two
|
133
|
+
CONFIG
|
134
|
+
|
135
|
+
@helper.write_source('one', 100, 25)
|
136
|
+
@helper.write_source('two', 100, 25)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should return an array with one element' do
|
140
|
+
@helper.project.sprites.should have(1).sprite
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should have two sources in the sprite' do
|
144
|
+
@helper.project.sprites.first.should have(2).sources
|
145
|
+
end
|
146
|
+
end # when the project has one sprite with two sources
|
147
|
+
|
148
|
+
context "when the project has two sprites with 2/1 sources" do
|
149
|
+
before(:each) do
|
150
|
+
@helper = Montage::Spec::ProjectHelper.new
|
151
|
+
@helper.write_config <<-CONFIG
|
152
|
+
---
|
153
|
+
sprite_one:
|
154
|
+
- one
|
155
|
+
- two
|
156
|
+
|
157
|
+
sprite_two:
|
158
|
+
- three
|
159
|
+
CONFIG
|
160
|
+
|
161
|
+
@helper.write_source('one', 100, 25)
|
162
|
+
@helper.write_source('two', 100, 25)
|
163
|
+
@helper.write_source('three', 100, 25)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should return an array with two elements' do
|
167
|
+
@helper.project.sprites.should have(2).sprite
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should have two sources in the first sprite' do
|
171
|
+
@helper.project.sprite('sprite_one').should have(2).sources
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should have one source in the second sprite' do
|
175
|
+
@helper.project.sprite('sprite_two').should have(1).sources
|
176
|
+
end
|
177
|
+
end # when the project has one sprite with two sources
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Montage::SassBuilder do
|
4
|
+
subject { Montage::SassBuilder }
|
5
|
+
|
6
|
+
# --- write ----------------------------------------------------------------
|
7
|
+
|
8
|
+
it { should have_public_method_defined(:write) }
|
9
|
+
|
10
|
+
describe '#write' do
|
11
|
+
before(:each) do
|
12
|
+
@helper = Montage::Spec::ProjectHelper.new
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with a project containing a single sprite and two sources' do
|
16
|
+
before(:each) do
|
17
|
+
@helper.write_config <<-CONFIG
|
18
|
+
---
|
19
|
+
only:
|
20
|
+
- one
|
21
|
+
- two
|
22
|
+
CONFIG
|
23
|
+
|
24
|
+
@helper.write_source('one')
|
25
|
+
@helper.write_source('two')
|
26
|
+
|
27
|
+
Montage::SassBuilder.new(@helper.project).write
|
28
|
+
|
29
|
+
@sass_path = @helper.path_to_file(
|
30
|
+
'public/stylesheets/sass/_montage.sass')
|
31
|
+
|
32
|
+
if @sass_path.file?
|
33
|
+
@sass = File.read(@helper.path_to_file(
|
34
|
+
'public/stylesheets/sass/_montage.sass'))
|
35
|
+
else
|
36
|
+
@sass = 'MISSING SASS FILE'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should save the Sass file' do
|
41
|
+
@sass_path.should be_file
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should contain the sprite mixin' do
|
45
|
+
@sass.should =~ /^=only-sprite/
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should include a condition for the "one" source' do
|
49
|
+
expected = Regexp.escape(
|
50
|
+
%[ @if $icon == "one"\n] +
|
51
|
+
%[ $y_offset: $y_offset - 0px])
|
52
|
+
|
53
|
+
@sass.should =~ /^#{expected}/
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should include a condition for the "two" source' do
|
57
|
+
expected = Regexp.escape(
|
58
|
+
%[ @else if $icon == "two"\n] +
|
59
|
+
%[ $y_offset: $y_offset - #{20 + @helper.project.padding}px])
|
60
|
+
|
61
|
+
@sass.should =~ /^#{expected}/
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should include the background statement' do
|
65
|
+
@sass.should include(
|
66
|
+
" background: url(/images/sprites/only.png)")
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'the generated mixins' do
|
70
|
+
it 'should correctly position the first source' do
|
71
|
+
sass = Sass::Engine.new(<<-SASS.unindent).render
|
72
|
+
@import #{@helper.project.paths.sass.realpath + '_montage.sass'}
|
73
|
+
|
74
|
+
.rule
|
75
|
+
+only-sprite("one")
|
76
|
+
SASS
|
77
|
+
|
78
|
+
sass.should include(
|
79
|
+
'background: url(/images/sprites/only.png) 0px 0px no-repeat')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should correctly position the second source' do
|
83
|
+
sass = Sass::Engine.new(<<-SASS.unindent).render
|
84
|
+
@import #{@helper.project.paths.sass.realpath + '_montage.sass'}
|
85
|
+
|
86
|
+
.rule
|
87
|
+
+only-sprite("two")
|
88
|
+
SASS
|
89
|
+
|
90
|
+
sass.should include(
|
91
|
+
'background: url(/images/sprites/only.png) 0px -40px no-repeat')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should apply x-offsets' do
|
95
|
+
sass = Sass::Engine.new(<<-SASS.unindent).render
|
96
|
+
@import #{@helper.project.paths.sass.realpath + '_montage.sass'}
|
97
|
+
|
98
|
+
.rule
|
99
|
+
+only-sprite("one", 5px)
|
100
|
+
SASS
|
101
|
+
|
102
|
+
sass.should include(
|
103
|
+
'background: url(/images/sprites/only.png) 5px 0px no-repeat')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should apply y-offsets' do
|
107
|
+
sass = Sass::Engine.new(<<-SASS.unindent).render
|
108
|
+
@import #{@helper.project.paths.sass.realpath + '_montage.sass'}
|
109
|
+
|
110
|
+
.rule
|
111
|
+
+only-sprite("two", 0px, -10px)
|
112
|
+
SASS
|
113
|
+
|
114
|
+
# -20px (source one) - 20px (padding) - 10px (third arg) = -50px
|
115
|
+
sass.should include(
|
116
|
+
'background: url(/images/sprites/only.png) 0px -50px no-repeat')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end # with a project containing a single sprite and two sources
|
120
|
+
|
121
|
+
context 'with a project containing two sprites, each with two sources' do
|
122
|
+
before(:each) do
|
123
|
+
@helper.write_config <<-CONFIG
|
124
|
+
---
|
125
|
+
first:
|
126
|
+
- one
|
127
|
+
- two
|
128
|
+
|
129
|
+
second:
|
130
|
+
- three
|
131
|
+
- four
|
132
|
+
CONFIG
|
133
|
+
|
134
|
+
%w( one two three four ).each do |source|
|
135
|
+
@helper.write_source(source)
|
136
|
+
end
|
137
|
+
|
138
|
+
Montage::SassBuilder.new(@helper.project).write
|
139
|
+
|
140
|
+
@sass_path = @helper.path_to_file(
|
141
|
+
'public/stylesheets/sass/_montage.sass')
|
142
|
+
|
143
|
+
if @sass_path.file?
|
144
|
+
@sass = File.read(@helper.path_to_file(
|
145
|
+
'public/stylesheets/sass/_montage.sass'))
|
146
|
+
else
|
147
|
+
@sass = 'MISSING SASS FILE'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should save the Sass file' do
|
152
|
+
@sass_path.should be_file
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should contain both sprite mixins' do
|
156
|
+
@sass.should =~ /^=first-sprite/
|
157
|
+
@sass.should =~ /^=second-sprite/
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should include a condition for the "one" source' do
|
161
|
+
expected = Regexp.escape(
|
162
|
+
%[ @if $icon == "one"\n] +
|
163
|
+
%[ $y_offset: $y_offset - 0px])
|
164
|
+
|
165
|
+
@sass.should =~ /^#{expected}/
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should include a condition for the "two" source' do
|
169
|
+
expected = Regexp.escape(
|
170
|
+
%[ @else if $icon == "two"\n] +
|
171
|
+
%[ $y_offset: $y_offset - #{20 + @helper.project.padding}px])
|
172
|
+
|
173
|
+
@sass.should =~ /^#{expected}/
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should include a condition for the "three" source' do
|
177
|
+
expected = Regexp.escape(
|
178
|
+
%[ @if $icon == "three"\n] +
|
179
|
+
%[ $y_offset: $y_offset - 0px])
|
180
|
+
|
181
|
+
@sass.should =~ /^#{expected}/
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should include a condition for the "four" source' do
|
185
|
+
expected = Regexp.escape(
|
186
|
+
%[ @else if $icon == "four"\n] +
|
187
|
+
%[ $y_offset: $y_offset - #{20 + @helper.project.padding}px])
|
188
|
+
|
189
|
+
@sass.should =~ /^#{expected}/
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should include the background statement for the first sprite' do
|
193
|
+
@sass.should include(
|
194
|
+
" background: url(/images/sprites/first.png)")
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should include the background statement for the second sprite' do
|
198
|
+
@sass.should include(
|
199
|
+
" background: url(/images/sprites/second.png)")
|
200
|
+
end
|
201
|
+
end # with a project containing two sprites, each with two sources
|
202
|
+
|
203
|
+
context 'with a project using a custom SASS location' do
|
204
|
+
before(:each) do
|
205
|
+
@helper.write_config <<-CONFIG
|
206
|
+
---
|
207
|
+
config.sass: "public/sass"
|
208
|
+
|
209
|
+
only:
|
210
|
+
- one
|
211
|
+
CONFIG
|
212
|
+
|
213
|
+
@helper.write_source('one')
|
214
|
+
Montage::SassBuilder.new(@helper.project).write
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should save the Sass file' do
|
218
|
+
@helper.path_to_file(
|
219
|
+
'public/sass/_montage.sass').should be_file
|
220
|
+
end
|
221
|
+
end # with a project using a custom SASS location
|
222
|
+
|
223
|
+
context 'with a project using a custom SASS location with a file name' do
|
224
|
+
before(:each) do
|
225
|
+
@helper.write_config <<-CONFIG
|
226
|
+
---
|
227
|
+
config.sass: "public/sass/_here.sass"
|
228
|
+
|
229
|
+
only:
|
230
|
+
- one
|
231
|
+
CONFIG
|
232
|
+
|
233
|
+
@helper.write_source('one')
|
234
|
+
Montage::SassBuilder.new(@helper.project).write
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should save the Sass file' do
|
238
|
+
@helper.path_to_file(
|
239
|
+
'public/sass/_here.sass').should be_file
|
240
|
+
end
|
241
|
+
end # with a project using a custom SASS location with a file name
|
242
|
+
|
243
|
+
context 'with a project using a custom sprite_url setting' do
|
244
|
+
before(:each) do
|
245
|
+
@helper.write_config <<-CONFIG
|
246
|
+
---
|
247
|
+
config.sprite_url: "/right/about/here"
|
248
|
+
|
249
|
+
only:
|
250
|
+
- one
|
251
|
+
CONFIG
|
252
|
+
|
253
|
+
@helper.write_source('one')
|
254
|
+
|
255
|
+
Montage::SassBuilder.new(@helper.project).write
|
256
|
+
|
257
|
+
@sass = File.read(@helper.path_to_file(
|
258
|
+
'public/stylesheets/sass/_montage.sass'))
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should include the background statement' do
|
262
|
+
@sass.should include(
|
263
|
+
" background: url(/right/about/here/only.png)")
|
264
|
+
end
|
265
|
+
end # with a project using a custom sprite_url setting
|
266
|
+
|
267
|
+
end # build
|
268
|
+
|
269
|
+
end
|