haml-edge 2.3.179 → 2.3.180

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/EDGE_GEM_VERSION +1 -1
  2. data/README.md +88 -149
  3. data/VERSION +1 -1
  4. data/bin/css2sass +7 -1
  5. data/bin/sass-convert +7 -0
  6. data/lib/haml/exec.rb +95 -22
  7. data/lib/haml/template.rb +1 -1
  8. data/lib/haml/util.rb +50 -0
  9. data/lib/sass.rb +1 -1
  10. data/lib/sass/css.rb +38 -210
  11. data/lib/sass/engine.rb +121 -47
  12. data/lib/sass/files.rb +28 -19
  13. data/lib/sass/plugin.rb +32 -43
  14. data/lib/sass/repl.rb +1 -1
  15. data/lib/sass/script.rb +25 -6
  16. data/lib/sass/script/bool.rb +1 -0
  17. data/lib/sass/script/color.rb +2 -2
  18. data/lib/sass/script/css_lexer.rb +22 -0
  19. data/lib/sass/script/css_parser.rb +28 -0
  20. data/lib/sass/script/funcall.rb +17 -9
  21. data/lib/sass/script/functions.rb +46 -1
  22. data/lib/sass/script/interpolation.rb +42 -0
  23. data/lib/sass/script/lexer.rb +142 -34
  24. data/lib/sass/script/literal.rb +28 -12
  25. data/lib/sass/script/node.rb +57 -1
  26. data/lib/sass/script/number.rb +18 -3
  27. data/lib/sass/script/operation.rb +44 -8
  28. data/lib/sass/script/parser.rb +149 -24
  29. data/lib/sass/script/string.rb +50 -2
  30. data/lib/sass/script/unary_operation.rb +25 -10
  31. data/lib/sass/script/variable.rb +20 -11
  32. data/lib/sass/scss.rb +14 -0
  33. data/lib/sass/scss/css_parser.rb +39 -0
  34. data/lib/sass/scss/parser.rb +683 -0
  35. data/lib/sass/scss/rx.rb +112 -0
  36. data/lib/sass/scss/script_lexer.rb +13 -0
  37. data/lib/sass/scss/script_parser.rb +25 -0
  38. data/lib/sass/tree/comment_node.rb +58 -16
  39. data/lib/sass/tree/debug_node.rb +7 -2
  40. data/lib/sass/tree/directive_node.rb +38 -34
  41. data/lib/sass/tree/for_node.rb +6 -0
  42. data/lib/sass/tree/if_node.rb +13 -0
  43. data/lib/sass/tree/import_node.rb +26 -7
  44. data/lib/sass/tree/mixin_def_node.rb +18 -0
  45. data/lib/sass/tree/mixin_node.rb +16 -1
  46. data/lib/sass/tree/node.rb +98 -27
  47. data/lib/sass/tree/prop_node.rb +97 -20
  48. data/lib/sass/tree/root_node.rb +37 -0
  49. data/lib/sass/tree/rule_node.rb +88 -60
  50. data/lib/sass/tree/variable_node.rb +9 -5
  51. data/lib/sass/tree/while_node.rb +4 -0
  52. data/test/haml/results/filters.xhtml +1 -1
  53. data/test/haml/util_test.rb +28 -0
  54. data/test/sass/conversion_test.rb +884 -0
  55. data/test/sass/css2sass_test.rb +46 -21
  56. data/test/sass/engine_test.rb +680 -160
  57. data/test/sass/functions_test.rb +27 -0
  58. data/test/sass/more_results/more_import.css +1 -1
  59. data/test/sass/more_templates/more_import.sass +3 -3
  60. data/test/sass/plugin_test.rb +28 -8
  61. data/test/sass/results/compact.css +1 -1
  62. data/test/sass/results/complex.css +5 -5
  63. data/test/sass/results/compressed.css +1 -1
  64. data/test/sass/results/expanded.css +1 -1
  65. data/test/sass/results/import.css +3 -1
  66. data/test/sass/results/mixins.css +12 -12
  67. data/test/sass/results/nested.css +1 -1
  68. data/test/sass/results/parent_ref.css +4 -4
  69. data/test/sass/results/script.css +3 -3
  70. data/test/sass/results/scss_import.css +15 -0
  71. data/test/sass/results/scss_importee.css +2 -0
  72. data/test/sass/script_conversion_test.rb +153 -0
  73. data/test/sass/script_test.rb +44 -54
  74. data/test/sass/scss/css_test.rb +811 -0
  75. data/test/sass/scss/rx_test.rb +156 -0
  76. data/test/sass/scss/scss_test.rb +871 -0
  77. data/test/sass/scss/test_helper.rb +37 -0
  78. data/test/sass/templates/alt.sass +2 -2
  79. data/test/sass/templates/bork1.sass +1 -1
  80. data/test/sass/templates/import.sass +4 -4
  81. data/test/sass/templates/importee.sass +3 -3
  82. data/test/sass/templates/line_numbers.sass +1 -1
  83. data/test/sass/templates/mixins.sass +2 -2
  84. data/test/sass/templates/nested_mixin_bork.sass +1 -1
  85. data/test/sass/templates/options.sass +1 -1
  86. data/test/sass/templates/parent_ref.sass +2 -2
  87. data/test/sass/templates/script.sass +69 -69
  88. data/test/sass/templates/scss_import.scss +10 -0
  89. data/test/sass/templates/scss_importee.scss +1 -0
  90. data/test/sass/templates/units.sass +10 -10
  91. data/test/test_helper.rb +4 -4
  92. metadata +27 -2
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.179
1
+ 2.3.180
data/README.md CHANGED
@@ -21,7 +21,7 @@ After you convert some HTML to Haml or some CSS to Sass,
21
21
  you can run
22
22
 
23
23
  haml document.haml
24
- sass style.sass
24
+ sass style.scss
25
25
 
26
26
  to compile them.
27
27
  For more information on these commands, check out
@@ -131,169 +131,107 @@ like `if` and `while`:
131
131
  Haml provides far more tools than those presented here.
132
132
  Check out the reference documentation in the Haml module.
133
133
 
134
- ### Sass
135
-
136
- At its most basic,
137
- Sass is just another way of writing CSS.
138
- Although it's very much like normal CSS,
139
- the basic syntax offers a few helpful features:
140
- indentation indicates the properties in a rule,
141
- rather than non-DRY brackets;
142
- and newlines indicate the end of a properties,
143
- rather than a semicolon.
144
- For example:
134
+ #### Indentation
145
135
 
146
- #main
147
- background-color: #f00
148
- width: 98%
136
+ Haml's indentation can be made up of one or more tabs or spaces.
137
+ However, indentation must be consistent within a given document.
138
+ Hard tabs and spaces can't be mixed,
139
+ and the same number of tabs or spaces must be used throughout.
149
140
 
150
- becomes:
141
+ ### Sass
151
142
 
152
- #main {
153
- background-color: #f00;
154
- width: 98% }
155
-
156
- However, Sass provides much more than a way to make CSS look nice.
157
- In CSS, it's important to have accurate selectors,
158
- so your styles don't just apply to everything.
159
- However, in order to do this,
160
- you need to use nested element selectors.
161
- These get very ugly very quickly.
162
- I'm sure everyone's had to write something like
163
- "#main .sidebar .top p h1 a",
164
- followed by
165
- "#main .sidebar .top p h1 a:visited" and
166
- "#main .sidebar .top p h1 a:hover".
167
- Well, Sass gets rid of that.
168
- Like Haml, it uses indentation to indicate the structure of the document.
169
- So, what was:
170
-
171
- #main {
172
- width: 90%;
143
+ Sass is an extension of CSS
144
+ that adds power and elegance to the basic language.
145
+ It allows you to use [variables][vars], [nested rules][nested],
146
+ [mixins][mixins], [inline imports][imports],
147
+ and more, all with a fully CSS-compatible syntax.
148
+ Sass helps keep large stylesheets well-organized,
149
+ and get small stylesheets up and running quickly,
150
+ particularly with the help of
151
+ [the Compass style library](http://compass-style.org).
152
+
153
+ [vars]: http://sass-lang.org/docs/yardoc/file.SASS_REFERENCE.md#variables_
154
+ [nested]: http://sass-lang.org/docs/yardoc/file.SASS_REFERENCE.md#nested_rules_
155
+ [mixins]: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins
156
+ [imports]: http://sass-lang.org/docs/yardoc/file.SASS_REFERENCE.md#import
157
+
158
+ Sass has two syntaxes.
159
+ The one presented here, known as "SCSS" (for "Sassy CSS"),
160
+ is fully CSS-compatible.
161
+ The other (older) syntax, known as the indented syntax or just "Sass",
162
+ is whitespace-sensitive and indentation-based.
163
+ For more information, see the [reference documentation][syntax].
164
+
165
+ [syntax]: http://sass-lang.org/docs/yardoc/file.SASS_REFERENCE.md#syntax
166
+
167
+ To run the following examples and see the CSS they produce,
168
+ put them in a file called `test.scss` and run `sass test.scss`.
169
+
170
+ #### Nesting
171
+
172
+ Sass avoids repetition by nesting selectors within one another.
173
+ The same thing works for properties.
174
+
175
+ table.hl {
176
+ margin: 2em 0;
177
+ td.ln { text-align: right; }
173
178
  }
174
- #main p {
175
- border-style: solid;
176
- border-width: 1px;
177
- border-color: #00f;
178
- }
179
- #main p a {
180
- text-decoration: none;
181
- font-weight: bold;
182
- }
183
- #main p a:hover {
184
- text-decoration: underline;
185
- }
186
-
187
- becomes:
188
-
189
- #main
190
- width: 90%
191
- p
192
- border-style: solid
193
- border-width: 1px
194
- border-color: #00f
195
- a
196
- text-decoration: none
197
- font-weight: bold
198
- a:hover
199
- text-decoration: underline
200
-
201
- Pretty nice, no? Well, it gets better.
202
- One of the main complaints against CSS is that it doesn't allow variables.
203
- What if have a color or a width you re-use all the time?
204
- In CSS, you just have to re-type it each time,
205
- which is a nightmare when you decide to change it later.
206
- Not so for Sass!
207
- You can use the `!` character to set variables.
208
- Then, if you put `=` after your property name,
209
- you can set it to a variable.
210
- For example:
211
-
212
- !note_bg= #55aaff
213
179
 
214
- #main
215
- width: 70%
216
- .note
217
- background-color = !note_bg
218
- p
219
- width: 5em
220
- background-color = !note_bg
221
-
222
- becomes:
223
-
224
- #main {
225
- width: 70%; }
226
- #main .note {
227
- background-color: #55aaff; }
228
- #main p {
229
- width: 5em;
230
- background-color: #55aaff; }
231
-
232
- You can even do simple arithmetic operations with variables,
233
- adding numbers and even colors together:
234
-
235
- !main_bg= #46ar12
236
- !main_width= 40em
237
-
238
- #main
239
- background-color = !main_bg
240
- width = !main_width
241
- .sidebar
242
- background-color = !main_bg + #333333
243
- width = !main_width - 25em
180
+ li {
181
+ font: {
182
+ family: serif;
183
+ weight: bold;
184
+ size: 1.2em;
185
+ }
186
+ }
244
187
 
245
- becomes:
188
+ #### Variables
246
189
 
247
- #main {
248
- background-color: #46a312;
249
- width: 40em; }
250
- #main .sidebar {
251
- background-color: #79d645;
252
- width: 15em; }
190
+ Use the same color all over the place?
191
+ Need to do some math with height and width and text size?
192
+ Sass supports variables, math operations, and many useful functions.
253
193
 
254
- Taking the idea of variables a bit further are mixins.
255
- These let you group whole bunches of CSS properties into a single
256
- directive and then include those anywhere you want:
194
+ $blue: #3bbfce;
195
+ $margin: 16px;
257
196
 
258
- =blue-border
259
- border:
260
- color: blue
261
- width: 2px
262
- style: dotted
197
+ .content_navigation {
198
+ border-color: $blue;
199
+ color: darken($blue, 10%);
200
+ }
263
201
 
264
- .comment
265
- +blue-border
266
- padding: 2px
267
- margin: 10px 0
202
+ .border {
203
+ padding: $margin / 2;
204
+ margin: $margin / 2;
205
+ border-color: $blue;
206
+ }
268
207
 
269
- .reply
270
- +blue-border
208
+ #### Mixins
271
209
 
272
- becomes:
210
+ Even more powerful than variables,
211
+ mixins allow you to re-use whole chunks of CSS,
212
+ properties or selectors.
213
+ You can even give them arguments.
273
214
 
274
- .comment {
275
- border-color: blue;
276
- border-width: 2px;
277
- border-style: dotted;
278
- padding: 2px;
279
- margin: 10px 0;
215
+ @mixin table-scaffolding {
216
+ th {
217
+ text-align: center;
218
+ font-weight: bold;
219
+ }
220
+ td, th { padding: 2px; }
280
221
  }
281
222
 
282
- .reply {
283
- border-color: blue;
284
- border-width: 2px;
285
- border-style: dotted;
223
+ @mixin left($dist) {
224
+ float: left;
225
+ margin-left: $dist;
286
226
  }
287
227
 
288
- A comprehensive list of features is in
289
- the documentation for the Sass module.
290
-
291
- ## Indentation
228
+ #data {
229
+ @include left(10px);
230
+ @include table-scaffolding;
231
+ }
292
232
 
293
- Indentation can be made up of one or more tabs or spaces.
294
- However, indentation must be consistent within a given document.
295
- Hard tabs and spaces can't be mixed,
296
- and the same number of tabs or spaces must be used throughout.
233
+ A comprehensive list of features is available
234
+ in the [Sass reference](http://sass-lang.org/docs/yardoc/file.SASS_REFERENCE.md).
297
235
 
298
236
  ## Executables
299
237
 
@@ -318,10 +256,11 @@ Since HTML is so variable, this transformation is not always perfect;
318
256
  it's a good idea to have a human check the output of this tool.
319
257
  See `html2haml --help` for further information and options.
320
258
 
321
- ### `css2sass`
259
+ ### `sass-convert`
322
260
 
323
- The `css2sass` executable attempts to transform CSS into Sass code.
324
- This transformation attempts to use Sass nesting where possible.
261
+ The `sass-convert` executable converts between CSS, Sass, and SCSS.
262
+ When converting from CSS to Sass or SCSS,
263
+ nesting is applied where appropriate.
325
264
  See `css2sass --help` for further information and options.
326
265
 
327
266
  ## Authors
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.179
1
+ 2.3.180
data/bin/css2sass CHANGED
@@ -3,5 +3,11 @@
3
3
  require File.dirname(__FILE__) + '/../lib/haml'
4
4
  require 'haml/exec'
5
5
 
6
- opts = Haml::Exec::CSS2Sass.new(ARGV)
6
+ warn <<END
7
+ DEPRECATION WARNING:
8
+ The css2sass tool is deprecated and will be removed in Sass 3.2.
9
+ Use the sass-convert tool instead.
10
+ END
11
+
12
+ opts = Haml::Exec::SassConvert.new(%w[--from css --to sass] + ARGV)
7
13
  opts.parse!
data/bin/sass-convert ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/haml'
4
+ require 'haml/exec'
5
+
6
+ opts = Haml::Exec::SassConvert.new(ARGV)
7
+ opts.parse!
data/lib/haml/exec.rb CHANGED
@@ -93,17 +93,14 @@ module Haml
93
93
  # so they can run their respective programs.
94
94
  def process_result
95
95
  input, output = @options[:input], @options[:output]
96
- input_file, output_file = if input
97
- [nil, open_file(@args[0], 'w')]
98
- else
99
- @options[:filename] = @args[0]
100
- [open_file(@args[0]), open_file(@args[1], 'w')]
101
- end
102
-
103
- input ||= input_file
104
- output ||= output_file
105
- input ||= $stdin
106
- output ||= $stdout
96
+ args = @args.dup
97
+ input ||=
98
+ begin
99
+ filename = args.shift
100
+ @options[:filename] = filename
101
+ open_file(filename) || $stdin
102
+ end
103
+ output ||= open_file(args.shift, 'w') || $stdout
107
104
 
108
105
  @options[:input], @options[:output] = input, output
109
106
  end
@@ -218,6 +215,10 @@ END
218
215
  def set_opts(opts)
219
216
  super
220
217
 
218
+ opts.on('--scss',
219
+ 'Use the CSS-superset SCSS syntax.') do
220
+ @options[:for_engine][:syntax] = :scss
221
+ end
221
222
  opts.on('--watch', 'Watch files or directories for changes.',
222
223
  'The location of the generated CSS can be set using a colon:',
223
224
  ' sass --watch input.sass:output.css',
@@ -275,6 +276,7 @@ END
275
276
  input = @options[:input]
276
277
  output = @options[:output]
277
278
 
279
+ @options[:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
278
280
  tree =
279
281
  if input.is_a?(File) && !@options[:check_syntax]
280
282
  ::Sass::Files.tree_for(input.path, @options[:for_engine])
@@ -533,12 +535,13 @@ END
533
535
  end
534
536
  end
535
537
 
536
- # The `css2sass` executable.
537
- class CSS2Sass < Generic
538
+ # The `sass-convert` executable.
539
+ class SassConvert < Generic
538
540
  # @param args [Array<String>] The command-line arguments
539
541
  def initialize(args)
540
542
  super
541
- @module_opts = {}
543
+ @options[:for_tree] = {}
544
+ @options[:for_engine] = {}
542
545
  end
543
546
 
544
547
  # Tells optparse how to parse the arguments.
@@ -546,18 +549,45 @@ END
546
549
  # @param opts [OptionParser]
547
550
  def set_opts(opts)
548
551
  opts.banner = <<END
549
- Usage: css2sass [options] [INPUT] [OUTPUT]
552
+ Usage: sass-convert [options] [INPUT] [OUTPUT]
550
553
 
551
- Description: Transforms a CSS file into corresponding Sass code.
554
+ Description:
555
+ Converts between CSS, Sass, and SCSS files.
556
+ E.g. converts from SCSS to Sass,
557
+ or converts from CSS to SCSS (adding appropriate nesting).
552
558
 
553
559
  Options:
554
560
  END
555
561
 
556
- opts.on('--old', 'Output the old-style ":prop val" property syntax') do
557
- @module_opts[:old] = true
562
+ opts.on('-F', '--from FORMAT',
563
+ 'The format to convert from. Can be css, scss, sass, or sass2.',
564
+ 'sass2 is the same as sass, but updates more old syntax to new.',
565
+ 'By default, this is inferred from the input filename.',
566
+ 'If there is none, defaults to css.') do |name|
567
+ @options[:from] = name.downcase.to_sym
568
+ end
569
+
570
+ opts.on('-T', '--to FORMAT',
571
+ 'The format to convert to. Can be scss or sass.',
572
+ 'By default, this is inferred from the output filename.',
573
+ 'If there is none, defaults to sass.') do |name|
574
+ @options[:to] = name.downcase.to_sym
558
575
  end
559
576
 
560
- opts.on_tail('-a', '--alternate', 'Ignored') {}
577
+ opts.on('-i', '--in-place',
578
+ 'Convert a file to its own syntax.',
579
+ 'This can be used to update some deprecated syntax.') do
580
+ @options[:in_place] = true
581
+ end
582
+
583
+ opts.on('--old', 'Output the old-style ":prop val" property syntax.',
584
+ 'Only meaningful when generating Sass.') do
585
+ @options[:for_tree][:old] = true
586
+ end
587
+
588
+ opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
589
+ @options[:for_engine][:cache] = false
590
+ end
561
591
 
562
592
  super
563
593
  end
@@ -565,14 +595,57 @@ END
565
595
  # Processes the options set by the command-line arguments,
566
596
  # and runs the CSS compiler appropriately.
567
597
  def process_result
598
+ require 'sass'
568
599
  super
569
600
 
570
- require 'sass/css'
571
-
572
601
  input = @options[:input]
573
602
  output = @options[:output]
603
+ output = input if @options[:in_place]
604
+
605
+ if input.is_a?(File)
606
+ @options[:from] ||=
607
+ case input.path
608
+ when /\.scss$/; :scss
609
+ when /\.sass$/; :sass
610
+ when /\.css$/; :css
611
+ end
612
+ elsif @options[:in_place]
613
+ raise "Error: the --in-place option requires a filename."
614
+ end
615
+
616
+ if output.is_a?(File)
617
+ @options[:to] ||=
618
+ case output.path
619
+ when /\.scss$/; :scss
620
+ when /\.sass$/; :sass
621
+ end
622
+ end
623
+
624
+ if @options[:from] == :sass2
625
+ @options[:from] = :sass
626
+ @options[:for_engine][:sass2] = true
627
+ end
628
+
629
+ @options[:from] ||= :css
630
+ @options[:to] ||= :sass
631
+ @options[:for_engine][:syntax] = @options[:from]
632
+
633
+ out =
634
+ ::Haml::Util.silence_haml_warnings do
635
+ if @options[:from] == :css
636
+ require 'sass/css'
637
+ ::Sass::CSS.new(input.read, @options[:for_tree]).render(@options[:to])
638
+ else
639
+ if input.is_a?(File)
640
+ ::Sass::Files.tree_for(input.path, @options[:for_engine])
641
+ else
642
+ ::Sass::Engine.new(input.read, @options[:for_engine]).to_tree
643
+ end.send("to_#{@options[:to]}", @options[:for_tree])
644
+ end
645
+ end
574
646
 
575
- output.write(::Sass::CSS.new(input, @module_opts).render)
647
+ output = File.open(input.path, 'w') if @options[:in_place]
648
+ output.write(out)
576
649
  rescue ::Sass::SyntaxError => e
577
650
  raise e if @options[:trace]
578
651
  raise "Syntax error on line #{get_line e}: #{e.message}\n Use --trace for backtrace"