haml 3.2.0.alpha.10 → 3.2.0.alpha.13
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/.yardopts +19 -7
- data/CHANGELOG.md +1224 -0
- data/FAQ.md +157 -0
- data/README.md +99 -62
- data/REFERENCE.md +1404 -0
- data/Rakefile +52 -341
- data/init.rb +1 -18
- data/lib/haml.rb +6 -30
- data/lib/haml/buffer.rb +37 -16
- data/lib/haml/compiler.rb +52 -13
- data/lib/haml/engine.rb +61 -44
- data/lib/haml/exec.rb +21 -4
- data/lib/haml/filters.rb +136 -166
- data/lib/haml/helpers.rb +37 -10
- data/lib/haml/helpers/action_view_extensions.rb +2 -1
- data/lib/haml/helpers/action_view_mods.rb +67 -181
- data/lib/haml/helpers/rails_323_textarea_fix.rb +39 -0
- data/lib/haml/helpers/xss_mods.rb +9 -11
- data/lib/haml/html.rb +22 -9
- data/lib/haml/html/erb.rb +1 -1
- data/lib/haml/parser.rb +22 -15
- data/lib/haml/railtie.rb +2 -13
- data/lib/haml/template.rb +18 -85
- data/lib/haml/template/options.rb +1 -1
- data/lib/haml/template/plugin.rb +15 -101
- data/lib/haml/util.rb +120 -603
- data/lib/haml/version.rb +1 -107
- data/test/{haml/engine_test.rb → engine_test.rb} +137 -143
- data/test/{haml/erb → erb}/_av_partial_1.erb +1 -1
- data/test/{haml/erb → erb}/_av_partial_2.erb +1 -1
- data/test/{haml/erb → erb}/action_view.erb +1 -1
- data/test/{haml/erb → erb}/standard.erb +0 -0
- data/test/filters_test.rb +141 -0
- data/test/gemfiles/Gemfile.rails-3.0.x +4 -6
- data/test/gemfiles/Gemfile.rails-3.1.x +5 -6
- data/test/gemfiles/Gemfile.rails-3.2.x +6 -0
- data/test/haml-spec/LICENSE +14 -0
- data/test/{haml/spec → haml-spec}/README.md +26 -17
- data/test/haml-spec/lua_haml_spec.lua +38 -0
- data/test/haml-spec/perl_haml_test.pl +81 -0
- data/test/haml-spec/ruby_haml_test.rb +23 -0
- data/test/{haml/spec → haml-spec}/tests.json +132 -54
- data/test/{haml/helper_test.rb → helper_test.rb} +50 -36
- data/test/{haml/html2haml → html2haml}/erb_tests.rb +0 -0
- data/test/{haml/html2haml_test.rb → html2haml_test.rb} +11 -5
- data/test/{haml/markaby → markaby}/standard.mab +0 -0
- data/test/{haml/mocks → mocks}/article.rb +0 -0
- data/test/{haml/results → results}/content_for_layout.xhtml +0 -0
- data/test/{haml/results → results}/eval_suppressed.xhtml +0 -0
- data/test/{haml/results → results}/helpers.xhtml +0 -0
- data/test/{haml/results → results}/helpful.xhtml +0 -0
- data/test/{haml/results → results}/just_stuff.xhtml +0 -0
- data/test/{haml/results → results}/list.xhtml +0 -0
- data/test/{haml/results → results}/nuke_inner_whitespace.xhtml +0 -0
- data/test/{haml/results → results}/nuke_outer_whitespace.xhtml +0 -0
- data/test/{haml/results → results}/original_engine.xhtml +0 -0
- data/test/{haml/results → results}/partial_layout.xhtml +0 -0
- data/test/{haml/results → results}/partials.xhtml +0 -0
- data/test/{haml/results → results}/render_layout.xhtml +0 -0
- data/test/{haml/results → results}/silent_script.xhtml +1 -1
- data/test/{haml/results → results}/standard.xhtml +0 -0
- data/test/{haml/results → results}/tag_parsing.xhtml +0 -0
- data/test/{haml/results → results}/very_basic.xhtml +0 -0
- data/test/{haml/results → results}/whitespace_handling.xhtml +46 -50
- data/test/{haml/template_test.rb → template_test.rb} +20 -81
- data/test/{haml/templates → templates}/_av_partial_1.haml +1 -1
- data/test/{haml/templates → templates}/_av_partial_1_ugly.haml +1 -1
- data/test/{haml/templates → templates}/_av_partial_2.haml +1 -1
- data/test/{haml/templates → templates}/_av_partial_2_ugly.haml +1 -1
- data/test/{haml/templates → templates}/_layout.erb +0 -0
- data/test/{haml/templates → templates}/_layout_for_partial.haml +0 -0
- data/test/{haml/templates → templates}/_partial.haml +0 -0
- data/test/{haml/templates → templates}/_text_area.haml +0 -0
- data/test/{haml/templates → templates}/action_view.haml +1 -1
- data/test/{haml/templates → templates}/action_view_ugly.haml +1 -1
- data/test/{haml/templates → templates}/breakage.haml +0 -0
- data/test/{haml/templates → templates}/content_for_layout.haml +0 -0
- data/test/{haml/templates → templates}/eval_suppressed.haml +0 -0
- data/test/{haml/templates → templates}/helpers.haml +0 -0
- data/test/{haml/templates → templates}/helpful.haml +0 -0
- data/test/{haml/templates → templates}/just_stuff.haml +0 -0
- data/test/{haml/templates → templates}/list.haml +0 -0
- data/test/{haml/templates → templates}/nuke_inner_whitespace.haml +0 -0
- data/test/{haml/templates → templates}/nuke_outer_whitespace.haml +0 -0
- data/test/{haml/templates → templates}/original_engine.haml +0 -0
- data/test/templates/partial_layout.haml +3 -0
- data/test/{haml/templates → templates}/partialize.haml +0 -0
- data/test/{haml/templates → templates}/partials.haml +0 -0
- data/test/{haml/templates → templates}/render_layout.haml +0 -0
- data/test/{haml/templates → templates}/silent_script.haml +2 -2
- data/test/{haml/templates → templates}/standard.haml +0 -0
- data/test/{haml/templates → templates}/standard_ugly.haml +0 -0
- data/test/{haml/templates → templates}/tag_parsing.haml +0 -0
- data/test/{haml/templates → templates}/very_basic.haml +0 -0
- data/test/{haml/templates → templates}/whitespace_handling.haml +0 -0
- data/test/test_helper.rb +42 -34
- data/test/util_test.rb +80 -0
- metadata +259 -427
- data/CONTRIBUTING +0 -3
- data/REVISION +0 -1
- data/VERSION +0 -1
- data/VERSION_NAME +0 -1
- data/extra/update_watch.rb +0 -13
- data/lib/haml/root.rb +0 -7
- data/lib/haml/shared.rb +0 -78
- data/lib/haml/template/patch.rb +0 -58
- data/lib/sass.rb +0 -8
- data/lib/sass/plugin.rb +0 -10
- data/lib/sass/rails2_shim.rb +0 -9
- data/lib/sass/rails3_shim.rb +0 -16
- data/test/benchmark.rb +0 -91
- data/test/gemfiles/Gemfile.rails-2.0.x +0 -8
- data/test/gemfiles/Gemfile.rails-2.0.x.lock +0 -38
- data/test/gemfiles/Gemfile.rails-2.1.x +0 -8
- data/test/gemfiles/Gemfile.rails-2.1.x.lock +0 -38
- data/test/gemfiles/Gemfile.rails-2.2.x +0 -8
- data/test/gemfiles/Gemfile.rails-2.2.x.lock +0 -38
- data/test/gemfiles/Gemfile.rails-2.3.x +0 -8
- data/test/gemfiles/Gemfile.rails-2.3.x.lock +0 -40
- data/test/gemfiles/Gemfile.rails-3.0.x.lock +0 -85
- data/test/gemfiles/Gemfile.rails-3.1.x.lock +0 -98
- data/test/gemfiles/Gemfile.rails-xss-2.3.x +0 -9
- data/test/gemfiles/Gemfile.rails-xss-2.3.x.lock +0 -42
- data/test/haml/results/filters.xhtml +0 -62
- data/test/haml/spec/lua_haml_spec.lua +0 -30
- data/test/haml/spec/ruby_haml_test.rb +0 -19
- data/test/haml/spec_test.rb +0 -44
- data/test/haml/templates/filters.haml +0 -66
- data/test/haml/templates/partial_layout.haml +0 -10
- data/test/haml/util_test.rb +0 -300
- data/test/linked_rails.rb +0 -42
- data/vendor/sass/CONTRIBUTING +0 -3
- data/vendor/sass/MIT-LICENSE +0 -20
- data/vendor/sass/README.md +0 -201
- data/vendor/sass/Rakefile +0 -339
- data/vendor/sass/TODO +0 -39
- data/vendor/sass/VERSION +0 -1
- data/vendor/sass/VERSION_NAME +0 -1
- data/vendor/sass/bin/sass +0 -8
- data/vendor/sass/bin/sass-convert +0 -7
- data/vendor/sass/bin/scss +0 -8
- data/vendor/sass/doc-src/FAQ.md +0 -35
- data/vendor/sass/doc-src/INDENTED_SYNTAX.md +0 -210
- data/vendor/sass/doc-src/SASS_CHANGELOG.md +0 -2327
- data/vendor/sass/doc-src/SASS_REFERENCE.md +0 -1965
- data/vendor/sass/doc-src/SCSS_FOR_SASS_USERS.md +0 -155
- data/vendor/sass/ext/extconf.rb +0 -10
- data/vendor/sass/extra/update_watch.rb +0 -13
- data/vendor/sass/init.rb +0 -18
- data/vendor/sass/lib/sass.rb +0 -73
- data/vendor/sass/lib/sass/cache_stores.rb +0 -15
- data/vendor/sass/lib/sass/cache_stores/base.rb +0 -86
- data/vendor/sass/lib/sass/cache_stores/chain.rb +0 -33
- data/vendor/sass/lib/sass/cache_stores/filesystem.rb +0 -60
- data/vendor/sass/lib/sass/cache_stores/memory.rb +0 -47
- data/vendor/sass/lib/sass/cache_stores/null.rb +0 -25
- data/vendor/sass/lib/sass/callbacks.rb +0 -66
- data/vendor/sass/lib/sass/css.rb +0 -295
- data/vendor/sass/lib/sass/engine.rb +0 -878
- data/vendor/sass/lib/sass/environment.rb +0 -166
- data/vendor/sass/lib/sass/error.rb +0 -201
- data/vendor/sass/lib/sass/exec.rb +0 -672
- data/vendor/sass/lib/sass/importers.rb +0 -22
- data/vendor/sass/lib/sass/importers/base.rb +0 -139
- data/vendor/sass/lib/sass/importers/filesystem.rb +0 -149
- data/vendor/sass/lib/sass/less.rb +0 -382
- data/vendor/sass/lib/sass/logger.rb +0 -15
- data/vendor/sass/lib/sass/logger/base.rb +0 -32
- data/vendor/sass/lib/sass/logger/log_level.rb +0 -49
- data/vendor/sass/lib/sass/plugin.rb +0 -132
- data/vendor/sass/lib/sass/plugin/compiler.rb +0 -383
- data/vendor/sass/lib/sass/plugin/configuration.rb +0 -123
- data/vendor/sass/lib/sass/plugin/generic.rb +0 -15
- data/vendor/sass/lib/sass/plugin/merb.rb +0 -48
- data/vendor/sass/lib/sass/plugin/rack.rb +0 -60
- data/vendor/sass/lib/sass/plugin/rails.rb +0 -47
- data/vendor/sass/lib/sass/plugin/staleness_checker.rb +0 -173
- data/vendor/sass/lib/sass/railtie.rb +0 -9
- data/vendor/sass/lib/sass/repl.rb +0 -58
- data/vendor/sass/lib/sass/root.rb +0 -7
- data/vendor/sass/lib/sass/script.rb +0 -40
- data/vendor/sass/lib/sass/script/bool.rb +0 -18
- data/vendor/sass/lib/sass/script/color.rb +0 -480
- data/vendor/sass/lib/sass/script/css_lexer.rb +0 -29
- data/vendor/sass/lib/sass/script/css_parser.rb +0 -31
- data/vendor/sass/lib/sass/script/funcall.rb +0 -175
- data/vendor/sass/lib/sass/script/functions.rb +0 -1386
- data/vendor/sass/lib/sass/script/interpolation.rb +0 -79
- data/vendor/sass/lib/sass/script/lexer.rb +0 -339
- data/vendor/sass/lib/sass/script/list.rb +0 -83
- data/vendor/sass/lib/sass/script/literal.rb +0 -250
- data/vendor/sass/lib/sass/script/node.rb +0 -99
- data/vendor/sass/lib/sass/script/number.rb +0 -452
- data/vendor/sass/lib/sass/script/operation.rb +0 -99
- data/vendor/sass/lib/sass/script/parser.rb +0 -474
- data/vendor/sass/lib/sass/script/string.rb +0 -51
- data/vendor/sass/lib/sass/script/string_interpolation.rb +0 -103
- data/vendor/sass/lib/sass/script/unary_operation.rb +0 -64
- data/vendor/sass/lib/sass/script/variable.rb +0 -59
- data/vendor/sass/lib/sass/scss.rb +0 -17
- data/vendor/sass/lib/sass/scss/css_parser.rb +0 -46
- data/vendor/sass/lib/sass/scss/parser.rb +0 -960
- data/vendor/sass/lib/sass/scss/rx.rb +0 -128
- data/vendor/sass/lib/sass/scss/sass_parser.rb +0 -11
- data/vendor/sass/lib/sass/scss/script_lexer.rb +0 -15
- data/vendor/sass/lib/sass/scss/script_parser.rb +0 -25
- data/vendor/sass/lib/sass/scss/static_parser.rb +0 -40
- data/vendor/sass/lib/sass/selector.rb +0 -361
- data/vendor/sass/lib/sass/selector/abstract_sequence.rb +0 -62
- data/vendor/sass/lib/sass/selector/comma_sequence.rb +0 -81
- data/vendor/sass/lib/sass/selector/sequence.rb +0 -233
- data/vendor/sass/lib/sass/selector/simple.rb +0 -113
- data/vendor/sass/lib/sass/selector/simple_sequence.rb +0 -134
- data/vendor/sass/lib/sass/shared.rb +0 -78
- data/vendor/sass/lib/sass/tree/charset_node.rb +0 -22
- data/vendor/sass/lib/sass/tree/comment_node.rb +0 -90
- data/vendor/sass/lib/sass/tree/debug_node.rb +0 -18
- data/vendor/sass/lib/sass/tree/directive_node.rb +0 -23
- data/vendor/sass/lib/sass/tree/each_node.rb +0 -24
- data/vendor/sass/lib/sass/tree/extend_node.rb +0 -29
- data/vendor/sass/lib/sass/tree/for_node.rb +0 -36
- data/vendor/sass/lib/sass/tree/function_node.rb +0 -27
- data/vendor/sass/lib/sass/tree/if_node.rb +0 -52
- data/vendor/sass/lib/sass/tree/import_node.rb +0 -68
- data/vendor/sass/lib/sass/tree/media_node.rb +0 -32
- data/vendor/sass/lib/sass/tree/mixin_def_node.rb +0 -27
- data/vendor/sass/lib/sass/tree/mixin_node.rb +0 -32
- data/vendor/sass/lib/sass/tree/node.rb +0 -201
- data/vendor/sass/lib/sass/tree/prop_node.rb +0 -148
- data/vendor/sass/lib/sass/tree/return_node.rb +0 -18
- data/vendor/sass/lib/sass/tree/root_node.rb +0 -28
- data/vendor/sass/lib/sass/tree/rule_node.rb +0 -136
- data/vendor/sass/lib/sass/tree/variable_node.rb +0 -30
- data/vendor/sass/lib/sass/tree/visitors/base.rb +0 -75
- data/vendor/sass/lib/sass/tree/visitors/check_nesting.rb +0 -133
- data/vendor/sass/lib/sass/tree/visitors/convert.rb +0 -260
- data/vendor/sass/lib/sass/tree/visitors/cssize.rb +0 -175
- data/vendor/sass/lib/sass/tree/visitors/deep_copy.rb +0 -87
- data/vendor/sass/lib/sass/tree/visitors/perform.rb +0 -332
- data/vendor/sass/lib/sass/tree/visitors/set_options.rb +0 -97
- data/vendor/sass/lib/sass/tree/visitors/to_css.rb +0 -210
- data/vendor/sass/lib/sass/tree/warn_node.rb +0 -18
- data/vendor/sass/lib/sass/tree/while_node.rb +0 -18
- data/vendor/sass/lib/sass/util.rb +0 -721
- data/vendor/sass/lib/sass/util/subset_map.rb +0 -101
- data/vendor/sass/lib/sass/version.rb +0 -112
- data/vendor/sass/rails/init.rb +0 -1
- data/vendor/sass/sass.gemspec +0 -33
- data/vendor/sass/test/Gemfile +0 -4
- data/vendor/sass/test/Gemfile.lock +0 -19
- data/vendor/sass/test/sass/cache_test.rb +0 -89
- data/vendor/sass/test/sass/callbacks_test.rb +0 -61
- data/vendor/sass/test/sass/conversion_test.rb +0 -1199
- data/vendor/sass/test/sass/css2sass_test.rb +0 -373
- data/vendor/sass/test/sass/data/hsl-rgb.txt +0 -319
- data/vendor/sass/test/sass/engine_test.rb +0 -2567
- data/vendor/sass/test/sass/extend_test.rb +0 -1348
- data/vendor/sass/test/sass/fixtures/test_staleness_check_across_importers.css +0 -1
- data/vendor/sass/test/sass/fixtures/test_staleness_check_across_importers.scss +0 -1
- data/vendor/sass/test/sass/functions_test.rb +0 -1038
- data/vendor/sass/test/sass/importer_test.rb +0 -192
- data/vendor/sass/test/sass/less_conversion_test.rb +0 -653
- data/vendor/sass/test/sass/logger_test.rb +0 -58
- data/vendor/sass/test/sass/mock_importer.rb +0 -49
- data/vendor/sass/test/sass/more_results/more1.css +0 -9
- data/vendor/sass/test/sass/more_results/more1_with_line_comments.css +0 -26
- data/vendor/sass/test/sass/more_results/more_import.css +0 -29
- data/vendor/sass/test/sass/more_templates/_more_partial.sass +0 -2
- data/vendor/sass/test/sass/more_templates/more1.sass +0 -23
- data/vendor/sass/test/sass/more_templates/more_import.sass +0 -11
- data/vendor/sass/test/sass/plugin_test.rb +0 -472
- data/vendor/sass/test/sass/results/alt.css +0 -4
- data/vendor/sass/test/sass/results/basic.css +0 -9
- data/vendor/sass/test/sass/results/compact.css +0 -5
- data/vendor/sass/test/sass/results/complex.css +0 -86
- data/vendor/sass/test/sass/results/compressed.css +0 -1
- data/vendor/sass/test/sass/results/expanded.css +0 -19
- data/vendor/sass/test/sass/results/if.css +0 -3
- data/vendor/sass/test/sass/results/import.css +0 -31
- data/vendor/sass/test/sass/results/import_charset.css +0 -4
- data/vendor/sass/test/sass/results/import_charset_1_8.css +0 -4
- data/vendor/sass/test/sass/results/import_charset_ibm866.css +0 -4
- data/vendor/sass/test/sass/results/line_numbers.css +0 -49
- data/vendor/sass/test/sass/results/mixins.css +0 -95
- data/vendor/sass/test/sass/results/multiline.css +0 -24
- data/vendor/sass/test/sass/results/nested.css +0 -22
- data/vendor/sass/test/sass/results/options.css +0 -1
- data/vendor/sass/test/sass/results/parent_ref.css +0 -13
- data/vendor/sass/test/sass/results/script.css +0 -16
- data/vendor/sass/test/sass/results/scss_import.css +0 -31
- data/vendor/sass/test/sass/results/scss_importee.css +0 -2
- data/vendor/sass/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
- data/vendor/sass/test/sass/results/subdir/subdir.css +0 -3
- data/vendor/sass/test/sass/results/units.css +0 -11
- data/vendor/sass/test/sass/results/warn.css +0 -0
- data/vendor/sass/test/sass/results/warn_imported.css +0 -0
- data/vendor/sass/test/sass/script_conversion_test.rb +0 -285
- data/vendor/sass/test/sass/script_test.rb +0 -514
- data/vendor/sass/test/sass/scss/css_test.rb +0 -922
- data/vendor/sass/test/sass/scss/rx_test.rb +0 -156
- data/vendor/sass/test/sass/scss/scss_test.rb +0 -1273
- data/vendor/sass/test/sass/scss/test_helper.rb +0 -37
- data/vendor/sass/test/sass/templates/_imported_charset_ibm866.sass +0 -4
- data/vendor/sass/test/sass/templates/_imported_charset_utf8.sass +0 -4
- data/vendor/sass/test/sass/templates/_partial.sass +0 -2
- data/vendor/sass/test/sass/templates/alt.sass +0 -16
- data/vendor/sass/test/sass/templates/basic.sass +0 -23
- data/vendor/sass/test/sass/templates/bork1.sass +0 -2
- data/vendor/sass/test/sass/templates/bork2.sass +0 -2
- data/vendor/sass/test/sass/templates/bork3.sass +0 -2
- data/vendor/sass/test/sass/templates/bork4.sass +0 -2
- data/vendor/sass/test/sass/templates/bork5.sass +0 -3
- data/vendor/sass/test/sass/templates/compact.sass +0 -17
- data/vendor/sass/test/sass/templates/complex.sass +0 -305
- data/vendor/sass/test/sass/templates/compressed.sass +0 -15
- data/vendor/sass/test/sass/templates/expanded.sass +0 -17
- data/vendor/sass/test/sass/templates/if.sass +0 -11
- data/vendor/sass/test/sass/templates/import.sass +0 -12
- data/vendor/sass/test/sass/templates/import_charset.sass +0 -7
- data/vendor/sass/test/sass/templates/import_charset_1_8.sass +0 -4
- data/vendor/sass/test/sass/templates/import_charset_ibm866.sass +0 -9
- data/vendor/sass/test/sass/templates/importee.less +0 -2
- data/vendor/sass/test/sass/templates/importee.sass +0 -19
- data/vendor/sass/test/sass/templates/line_numbers.sass +0 -13
- data/vendor/sass/test/sass/templates/mixin_bork.sass +0 -5
- data/vendor/sass/test/sass/templates/mixins.sass +0 -76
- data/vendor/sass/test/sass/templates/multiline.sass +0 -20
- data/vendor/sass/test/sass/templates/nested.sass +0 -25
- data/vendor/sass/test/sass/templates/nested_bork1.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork2.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork3.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork4.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork5.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_import.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_mixin_bork.sass +0 -6
- data/vendor/sass/test/sass/templates/options.sass +0 -2
- data/vendor/sass/test/sass/templates/parent_ref.sass +0 -25
- data/vendor/sass/test/sass/templates/script.sass +0 -101
- data/vendor/sass/test/sass/templates/scss_import.scss +0 -11
- data/vendor/sass/test/sass/templates/scss_importee.scss +0 -1
- data/vendor/sass/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
- data/vendor/sass/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
- data/vendor/sass/test/sass/templates/subdir/subdir.sass +0 -6
- data/vendor/sass/test/sass/templates/units.sass +0 -11
- data/vendor/sass/test/sass/templates/warn.sass +0 -3
- data/vendor/sass/test/sass/templates/warn_imported.sass +0 -4
- data/vendor/sass/test/sass/test_helper.rb +0 -8
- data/vendor/sass/test/sass/util/subset_map_test.rb +0 -91
- data/vendor/sass/test/sass/util_test.rb +0 -266
- data/vendor/sass/test/test_helper.rb +0 -69
- data/vendor/sass/vendor/fssm/Gemfile +0 -3
- data/vendor/sass/vendor/fssm/LICENSE +0 -20
- data/vendor/sass/vendor/fssm/README.markdown +0 -83
- data/vendor/sass/vendor/fssm/Rakefile +0 -11
- data/vendor/sass/vendor/fssm/example.rb +0 -12
- data/vendor/sass/vendor/fssm/fssm.gemspec +0 -24
- data/vendor/sass/vendor/fssm/lib/fssm.rb +0 -37
- data/vendor/sass/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
- data/vendor/sass/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
- data/vendor/sass/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
- data/vendor/sass/vendor/fssm/lib/fssm/backends/rbfsevent.rb +0 -42
- data/vendor/sass/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
- data/vendor/sass/vendor/fssm/lib/fssm/monitor.rb +0 -36
- data/vendor/sass/vendor/fssm/lib/fssm/path.rb +0 -94
- data/vendor/sass/vendor/fssm/lib/fssm/pathname.rb +0 -36
- data/vendor/sass/vendor/fssm/lib/fssm/state/directory.rb +0 -75
- data/vendor/sass/vendor/fssm/lib/fssm/state/file.rb +0 -24
- data/vendor/sass/vendor/fssm/lib/fssm/support.rb +0 -92
- data/vendor/sass/vendor/fssm/lib/fssm/tree.rb +0 -176
- data/vendor/sass/vendor/fssm/lib/fssm/version.rb +0 -3
- data/vendor/sass/vendor/fssm/profile/prof-cache.rb +0 -40
- data/vendor/sass/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
- data/vendor/sass/vendor/fssm/profile/prof-pathname-rubinius.rb +0 -35
- data/vendor/sass/vendor/fssm/profile/prof-pathname.rb +0 -68
- data/vendor/sass/vendor/fssm/profile/prof-plain-pathname.html +0 -988
- data/vendor/sass/vendor/fssm/profile/prof.html +0 -2379
- data/vendor/sass/vendor/fssm/spec/count_down_latch.rb +0 -151
- data/vendor/sass/vendor/fssm/spec/monitor_spec.rb +0 -202
- data/vendor/sass/vendor/fssm/spec/path_spec.rb +0 -96
- data/vendor/sass/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/sass/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/sass/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/sass/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/sass/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/sass/vendor/fssm/spec/spec_helper.rb +0 -14
- data/vendor/sass/yard/callbacks.rb +0 -29
- data/vendor/sass/yard/default/fulldoc/html/css/common.sass +0 -26
- data/vendor/sass/yard/default/layout/html/footer.erb +0 -12
- data/vendor/sass/yard/inherited_hash.rb +0 -41
@@ -1,250 +0,0 @@
|
|
1
|
-
module Sass::Script
|
2
|
-
# The abstract superclass for SassScript objects.
|
3
|
-
#
|
4
|
-
# Many of these methods, especially the ones that correspond to SassScript operations,
|
5
|
-
# are designed to be overridden by subclasses which may change the semantics somewhat.
|
6
|
-
# The operations listed here are just the defaults.
|
7
|
-
class Literal < Node
|
8
|
-
require 'sass/script/string'
|
9
|
-
require 'sass/script/number'
|
10
|
-
require 'sass/script/color'
|
11
|
-
require 'sass/script/bool'
|
12
|
-
require 'sass/script/list'
|
13
|
-
|
14
|
-
# Returns the Ruby value of the literal.
|
15
|
-
# The type of this value varies based on the subclass.
|
16
|
-
#
|
17
|
-
# @return [Object]
|
18
|
-
attr_reader :value
|
19
|
-
|
20
|
-
# Creates a new literal.
|
21
|
-
#
|
22
|
-
# @param value [Object] The object for \{#value}
|
23
|
-
def initialize(value = nil)
|
24
|
-
@value = value
|
25
|
-
super()
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns an empty array.
|
29
|
-
#
|
30
|
-
# @return [Array<Node>] empty
|
31
|
-
# @see Node#children
|
32
|
-
def children
|
33
|
-
[]
|
34
|
-
end
|
35
|
-
|
36
|
-
# @see Node#deep_copy
|
37
|
-
def deep_copy
|
38
|
-
dup
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns the options hash for this node.
|
42
|
-
#
|
43
|
-
# @return [{Symbol => Object}]
|
44
|
-
# @raise [Sass::SyntaxError] if the options hash hasn't been set.
|
45
|
-
# This should only happen when the literal was created
|
46
|
-
# outside of the parser and \{#to\_s} was called on it
|
47
|
-
def options
|
48
|
-
opts = super
|
49
|
-
return opts if opts
|
50
|
-
raise Sass::SyntaxError.new(<<MSG)
|
51
|
-
The #options attribute is not set on this #{self.class}.
|
52
|
-
This error is probably occurring because #to_s was called
|
53
|
-
on this literal within a custom Sass function without first
|
54
|
-
setting the #option attribute.
|
55
|
-
MSG
|
56
|
-
end
|
57
|
-
|
58
|
-
# The SassScript `and` operation.
|
59
|
-
#
|
60
|
-
# @param other [Literal] The right-hand side of the operator
|
61
|
-
# @return [Literal] The result of a logical and:
|
62
|
-
# `other` if this literal isn't a false {Bool},
|
63
|
-
# and this literal otherwise
|
64
|
-
def and(other)
|
65
|
-
to_bool ? other : self
|
66
|
-
end
|
67
|
-
|
68
|
-
# The SassScript `or` operation.
|
69
|
-
#
|
70
|
-
# @param other [Literal] The right-hand side of the operator
|
71
|
-
# @return [Literal] The result of the logical or:
|
72
|
-
# this literal if it isn't a false {Bool},
|
73
|
-
# and `other` otherwise
|
74
|
-
def or(other)
|
75
|
-
to_bool ? self : other
|
76
|
-
end
|
77
|
-
|
78
|
-
# The SassScript `==` operation.
|
79
|
-
# **Note that this returns a {Sass::Script::Bool} object,
|
80
|
-
# not a Ruby boolean**.
|
81
|
-
#
|
82
|
-
# @param other [Literal] The right-hand side of the operator
|
83
|
-
# @return [Bool] True if this literal is the same as the other,
|
84
|
-
# false otherwise
|
85
|
-
def eq(other)
|
86
|
-
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
|
87
|
-
end
|
88
|
-
|
89
|
-
# The SassScript `!=` operation.
|
90
|
-
# **Note that this returns a {Sass::Script::Bool} object,
|
91
|
-
# not a Ruby boolean**.
|
92
|
-
#
|
93
|
-
# @param other [Literal] The right-hand side of the operator
|
94
|
-
# @return [Bool] False if this literal is the same as the other,
|
95
|
-
# true otherwise
|
96
|
-
def neq(other)
|
97
|
-
Sass::Script::Bool.new(!eq(other).to_bool)
|
98
|
-
end
|
99
|
-
|
100
|
-
# The SassScript `==` operation.
|
101
|
-
# **Note that this returns a {Sass::Script::Bool} object,
|
102
|
-
# not a Ruby boolean**.
|
103
|
-
#
|
104
|
-
# @param other [Literal] The right-hand side of the operator
|
105
|
-
# @return [Bool] True if this literal is the same as the other,
|
106
|
-
# false otherwise
|
107
|
-
def unary_not
|
108
|
-
Sass::Script::Bool.new(!to_bool)
|
109
|
-
end
|
110
|
-
|
111
|
-
# The SassScript default operation (e.g. `$a $b`, `"foo" "bar"`).
|
112
|
-
#
|
113
|
-
# @param other [Literal] The right-hand side of the operator
|
114
|
-
# @return [Script::String] A string containing both literals
|
115
|
-
# separated by a space
|
116
|
-
def space(other)
|
117
|
-
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
|
118
|
-
end
|
119
|
-
|
120
|
-
# The SassScript `,` operation (e.g. `$a, $b`, `"foo", "bar"`).
|
121
|
-
#
|
122
|
-
# @param other [Literal] The right-hand side of the operator
|
123
|
-
# @return [Script::String] A string containing both literals
|
124
|
-
# separated by `", "`
|
125
|
-
def comma(other)
|
126
|
-
Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
|
127
|
-
end
|
128
|
-
|
129
|
-
# The SassScript `=` operation
|
130
|
-
# (used for proprietary MS syntax like `alpha(opacity=20)`).
|
131
|
-
#
|
132
|
-
# @param other [Literal] The right-hand side of the operator
|
133
|
-
# @return [Script::String] A string containing both literals
|
134
|
-
# separated by `"="`
|
135
|
-
def single_eq(other)
|
136
|
-
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
|
137
|
-
end
|
138
|
-
|
139
|
-
# The SassScript `+` operation.
|
140
|
-
#
|
141
|
-
# @param other [Literal] The right-hand side of the operator
|
142
|
-
# @return [Script::String] A string containing both literals
|
143
|
-
# without any separation
|
144
|
-
def plus(other)
|
145
|
-
if other.is_a?(Sass::Script::String)
|
146
|
-
return Sass::Script::String.new(self.to_s + other.value, other.type)
|
147
|
-
end
|
148
|
-
Sass::Script::String.new(self.to_s + other.to_s)
|
149
|
-
end
|
150
|
-
|
151
|
-
# The SassScript `-` operation.
|
152
|
-
#
|
153
|
-
# @param other [Literal] The right-hand side of the operator
|
154
|
-
# @return [Script::String] A string containing both literals
|
155
|
-
# separated by `"-"`
|
156
|
-
def minus(other)
|
157
|
-
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
|
158
|
-
end
|
159
|
-
|
160
|
-
# The SassScript `/` operation.
|
161
|
-
#
|
162
|
-
# @param other [Literal] The right-hand side of the operator
|
163
|
-
# @return [Script::String] A string containing both literals
|
164
|
-
# separated by `"/"`
|
165
|
-
def div(other)
|
166
|
-
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
|
167
|
-
end
|
168
|
-
|
169
|
-
# The SassScript unary `+` operation (e.g. `+$a`).
|
170
|
-
#
|
171
|
-
# @param other [Literal] The right-hand side of the operator
|
172
|
-
# @return [Script::String] A string containing the literal
|
173
|
-
# preceded by `"+"`
|
174
|
-
def unary_plus
|
175
|
-
Sass::Script::String.new("+#{self.to_s}")
|
176
|
-
end
|
177
|
-
|
178
|
-
# The SassScript unary `-` operation (e.g. `-$a`).
|
179
|
-
#
|
180
|
-
# @param other [Literal] The right-hand side of the operator
|
181
|
-
# @return [Script::String] A string containing the literal
|
182
|
-
# preceded by `"-"`
|
183
|
-
def unary_minus
|
184
|
-
Sass::Script::String.new("-#{self.to_s}")
|
185
|
-
end
|
186
|
-
|
187
|
-
# The SassScript unary `/` operation (e.g. `/$a`).
|
188
|
-
#
|
189
|
-
# @param other [Literal] The right-hand side of the operator
|
190
|
-
# @return [Script::String] A string containing the literal
|
191
|
-
# preceded by `"/"`
|
192
|
-
def unary_div
|
193
|
-
Sass::Script::String.new("/#{self.to_s}")
|
194
|
-
end
|
195
|
-
|
196
|
-
# @return [String] A readable representation of the literal
|
197
|
-
def inspect
|
198
|
-
value.inspect
|
199
|
-
end
|
200
|
-
|
201
|
-
# @return [Boolean] `true` (the Ruby boolean value)
|
202
|
-
def to_bool
|
203
|
-
true
|
204
|
-
end
|
205
|
-
|
206
|
-
# Compares this object with another.
|
207
|
-
#
|
208
|
-
# @param other [Object] The object to compare with
|
209
|
-
# @return [Boolean] Whether or not this literal is equivalent to `other`
|
210
|
-
def ==(other)
|
211
|
-
eq(other).to_bool
|
212
|
-
end
|
213
|
-
|
214
|
-
# @return [Fixnum] The integer value of this literal
|
215
|
-
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
216
|
-
def to_i
|
217
|
-
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
218
|
-
end
|
219
|
-
|
220
|
-
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
221
|
-
def assert_int!; to_i; end
|
222
|
-
|
223
|
-
# Returns the value of this literal as a list.
|
224
|
-
# Single literals are considered the same as single-element lists.
|
225
|
-
#
|
226
|
-
# @return [Array<Literal>] The of this literal as a list
|
227
|
-
def to_a
|
228
|
-
[self]
|
229
|
-
end
|
230
|
-
|
231
|
-
# Returns the string representation of this literal
|
232
|
-
# as it would be output to the CSS document.
|
233
|
-
#
|
234
|
-
# @return [String]
|
235
|
-
def to_s(opts = {})
|
236
|
-
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
|
237
|
-
end
|
238
|
-
alias_method :to_sass, :to_s
|
239
|
-
|
240
|
-
protected
|
241
|
-
|
242
|
-
# Evaluates the literal.
|
243
|
-
#
|
244
|
-
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
245
|
-
# @return [Literal] This literal
|
246
|
-
def _perform(environment)
|
247
|
-
self
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
module Sass::Script
|
2
|
-
# The abstract superclass for SassScript parse tree nodes.
|
3
|
-
#
|
4
|
-
# Use \{#perform} to evaluate a parse tree.
|
5
|
-
class Node
|
6
|
-
# The options hash for this node.
|
7
|
-
#
|
8
|
-
# @return [{Symbol => Object}]
|
9
|
-
attr_reader :options
|
10
|
-
|
11
|
-
# The line of the document on which this node appeared.
|
12
|
-
#
|
13
|
-
# @return [Fixnum]
|
14
|
-
attr_accessor :line
|
15
|
-
|
16
|
-
# Sets the options hash for this node,
|
17
|
-
# as well as for all child nodes.
|
18
|
-
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
19
|
-
#
|
20
|
-
# @param options [{Symbol => Object}] The options
|
21
|
-
def options=(options)
|
22
|
-
@options = options
|
23
|
-
children.each do |c|
|
24
|
-
if c.is_a? Hash
|
25
|
-
c.values.each {|v| v.options = options }
|
26
|
-
else
|
27
|
-
c.options = options
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Evaluates the node.
|
33
|
-
#
|
34
|
-
# \{#perform} shouldn't be overridden directly;
|
35
|
-
# instead, override \{#\_perform}.
|
36
|
-
#
|
37
|
-
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
38
|
-
# @return [Literal] The SassScript object that is the value of the SassScript
|
39
|
-
def perform(environment)
|
40
|
-
_perform(environment)
|
41
|
-
rescue Sass::SyntaxError => e
|
42
|
-
e.modify_backtrace(:line => line)
|
43
|
-
raise e
|
44
|
-
end
|
45
|
-
|
46
|
-
# Returns all child nodes of this node.
|
47
|
-
#
|
48
|
-
# @return [Array<Node>]
|
49
|
-
def children
|
50
|
-
Sass::Util.abstract(self)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Returns the text of this SassScript expression.
|
54
|
-
#
|
55
|
-
# @return [String]
|
56
|
-
def to_sass(opts = {})
|
57
|
-
Sass::Util.abstract(self)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns a deep clone of this node.
|
61
|
-
# The child nodes are cloned, but options are not.
|
62
|
-
#
|
63
|
-
# @return [Node]
|
64
|
-
def deep_copy
|
65
|
-
Sass::Util.abstract(self)
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
# Converts underscores to dashes if the :dasherize option is set.
|
71
|
-
def dasherize(s, opts)
|
72
|
-
if opts[:dasherize]
|
73
|
-
s.gsub(/_/,'-')
|
74
|
-
else
|
75
|
-
s
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# Evaluates this node.
|
80
|
-
# Note that all {Literal} objects created within this method
|
81
|
-
# should have their \{#options} attribute set, probably via \{#opts}.
|
82
|
-
#
|
83
|
-
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
84
|
-
# @return [Literal] The SassScript object that is the value of the SassScript
|
85
|
-
# @see #perform
|
86
|
-
def _perform(environment)
|
87
|
-
Sass::Util.abstract(self)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Sets the \{#options} field on the given literal and returns it
|
91
|
-
#
|
92
|
-
# @param literal [Literal]
|
93
|
-
# @return [Literal]
|
94
|
-
def opts(literal)
|
95
|
-
literal.options = options
|
96
|
-
literal
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,452 +0,0 @@
|
|
1
|
-
require 'sass/script/literal'
|
2
|
-
|
3
|
-
module Sass::Script
|
4
|
-
# A SassScript object representing a number.
|
5
|
-
# SassScript numbers can have decimal values,
|
6
|
-
# and can also have units.
|
7
|
-
# For example, `12`, `1px`, and `10.45em`
|
8
|
-
# are all valid values.
|
9
|
-
#
|
10
|
-
# Numbers can also have more complex units, such as `1px*em/in`.
|
11
|
-
# These cannot be inputted directly in Sass code at the moment.
|
12
|
-
class Number < Literal
|
13
|
-
# The Ruby value of the number.
|
14
|
-
#
|
15
|
-
# @return [Numeric]
|
16
|
-
attr_reader :value
|
17
|
-
|
18
|
-
# A list of units in the numerator of the number.
|
19
|
-
# For example, `1px*em/in*cm` would return `["px", "em"]`
|
20
|
-
# @return [Array<String>]
|
21
|
-
attr_reader :numerator_units
|
22
|
-
|
23
|
-
# A list of units in the denominator of the number.
|
24
|
-
# For example, `1px*em/in*cm` would return `["in", "cm"]`
|
25
|
-
# @return [Array<String>]
|
26
|
-
attr_reader :denominator_units
|
27
|
-
|
28
|
-
# The original representation of this number.
|
29
|
-
# For example, although the result of `1px/2px` is `0.5`,
|
30
|
-
# the value of `#original` is `"1px/2px"`.
|
31
|
-
#
|
32
|
-
# This is only non-nil when the original value should be used as the CSS value,
|
33
|
-
# as in `font: 1px/2px`.
|
34
|
-
#
|
35
|
-
# @return [Boolean, nil]
|
36
|
-
attr_accessor :original
|
37
|
-
|
38
|
-
def self.precision
|
39
|
-
@precision ||= 3
|
40
|
-
end
|
41
|
-
|
42
|
-
# Sets the number of digits of precision
|
43
|
-
# For example, if this is `3`,
|
44
|
-
# `3.1415926` will be printed as `3.142`.
|
45
|
-
def self.precision=(digits)
|
46
|
-
@precision = digits.round
|
47
|
-
@precision_factor = 10.0**@precision
|
48
|
-
end
|
49
|
-
|
50
|
-
# the precision factor used in numeric output
|
51
|
-
# it is derived from the `precision` method.
|
52
|
-
def self.precision_factor
|
53
|
-
@precision_factor ||= 10.0**precision
|
54
|
-
end
|
55
|
-
|
56
|
-
# Handles the deprecation warning for the PRECISION constant
|
57
|
-
# This can be removed in 3.2.
|
58
|
-
def self.const_missing(const)
|
59
|
-
if const == :PRECISION
|
60
|
-
Sass::Util.sass_warn("Sass::Script::Number::PRECISION is deprecated and will be removed in a future release. Use Sass::Script::Number.precision_factor instead.")
|
61
|
-
const_set(:PRECISION, self.precision_factor)
|
62
|
-
else
|
63
|
-
super
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Used so we don't allocate two new arrays for each new number.
|
68
|
-
NO_UNITS = []
|
69
|
-
|
70
|
-
# @param value [Numeric] The value of the number
|
71
|
-
# @param numerator_units [Array<String>] See \{#numerator\_units}
|
72
|
-
# @param denominator_units [Array<String>] See \{#denominator\_units}
|
73
|
-
def initialize(value, numerator_units = NO_UNITS, denominator_units = NO_UNITS)
|
74
|
-
super(value)
|
75
|
-
@numerator_units = numerator_units
|
76
|
-
@denominator_units = denominator_units
|
77
|
-
normalize!
|
78
|
-
end
|
79
|
-
|
80
|
-
# The SassScript `+` operation.
|
81
|
-
# Its functionality depends on the type of its argument:
|
82
|
-
#
|
83
|
-
# {Number}
|
84
|
-
# : Adds the two numbers together, converting units if possible.
|
85
|
-
#
|
86
|
-
# {Color}
|
87
|
-
# : Adds this number to each of the RGB color channels.
|
88
|
-
#
|
89
|
-
# {Literal}
|
90
|
-
# : See {Literal#plus}.
|
91
|
-
#
|
92
|
-
# @param other [Literal] The right-hand side of the operator
|
93
|
-
# @return [Literal] The result of the operation
|
94
|
-
# @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
|
95
|
-
def plus(other)
|
96
|
-
if other.is_a? Number
|
97
|
-
operate(other, :+)
|
98
|
-
elsif other.is_a?(Color)
|
99
|
-
other.plus(self)
|
100
|
-
else
|
101
|
-
super
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# The SassScript binary `-` operation (e.g. `$a - $b`).
|
106
|
-
# Its functionality depends on the type of its argument:
|
107
|
-
#
|
108
|
-
# {Number}
|
109
|
-
# : Subtracts this number from the other, converting units if possible.
|
110
|
-
#
|
111
|
-
# {Literal}
|
112
|
-
# : See {Literal#minus}.
|
113
|
-
#
|
114
|
-
# @param other [Literal] The right-hand side of the operator
|
115
|
-
# @return [Literal] The result of the operation
|
116
|
-
# @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
|
117
|
-
def minus(other)
|
118
|
-
if other.is_a? Number
|
119
|
-
operate(other, :-)
|
120
|
-
else
|
121
|
-
super
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# The SassScript unary `+` operation (e.g. `+$a`).
|
126
|
-
#
|
127
|
-
# @return [Number] The value of this number
|
128
|
-
def unary_plus
|
129
|
-
self
|
130
|
-
end
|
131
|
-
|
132
|
-
# The SassScript unary `-` operation (e.g. `-$a`).
|
133
|
-
#
|
134
|
-
# @return [Number] The negative value of this number
|
135
|
-
def unary_minus
|
136
|
-
Number.new(-value, @numerator_units, @denominator_units)
|
137
|
-
end
|
138
|
-
|
139
|
-
# The SassScript `*` operation.
|
140
|
-
# Its functionality depends on the type of its argument:
|
141
|
-
#
|
142
|
-
# {Number}
|
143
|
-
# : Multiplies the two numbers together, converting units appropriately.
|
144
|
-
#
|
145
|
-
# {Color}
|
146
|
-
# : Multiplies each of the RGB color channels by this number.
|
147
|
-
#
|
148
|
-
# @param other [Number, Color] The right-hand side of the operator
|
149
|
-
# @return [Number, Color] The result of the operation
|
150
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
151
|
-
def times(other)
|
152
|
-
if other.is_a? Number
|
153
|
-
operate(other, :*)
|
154
|
-
elsif other.is_a? Color
|
155
|
-
other.times(self)
|
156
|
-
else
|
157
|
-
raise NoMethodError.new(nil, :times)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
# The SassScript `/` operation.
|
162
|
-
# Its functionality depends on the type of its argument:
|
163
|
-
#
|
164
|
-
# {Number}
|
165
|
-
# : Divides this number by the other, converting units appropriately.
|
166
|
-
#
|
167
|
-
# {Literal}
|
168
|
-
# : See {Literal#div}.
|
169
|
-
#
|
170
|
-
# @param other [Literal] The right-hand side of the operator
|
171
|
-
# @return [Literal] The result of the operation
|
172
|
-
def div(other)
|
173
|
-
if other.is_a? Number
|
174
|
-
res = operate(other, :/)
|
175
|
-
if self.original && other.original
|
176
|
-
res.original = "#{self.original}/#{other.original}"
|
177
|
-
end
|
178
|
-
res
|
179
|
-
else
|
180
|
-
super
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# The SassScript `%` operation.
|
185
|
-
#
|
186
|
-
# @param other [Number] The right-hand side of the operator
|
187
|
-
# @return [Number] This number modulo the other
|
188
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
189
|
-
# @raise [Sass::UnitConversionError] if `other` has any units
|
190
|
-
def mod(other)
|
191
|
-
if other.is_a?(Number)
|
192
|
-
unless other.unitless?
|
193
|
-
raise Sass::UnitConversionError.new("Cannot modulo by a number with units: #{other.inspect}.")
|
194
|
-
end
|
195
|
-
operate(other, :%)
|
196
|
-
else
|
197
|
-
raise NoMethodError.new(nil, :mod)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# The SassScript `==` operation.
|
202
|
-
#
|
203
|
-
# @param other [Literal] The right-hand side of the operator
|
204
|
-
# @return [Boolean] Whether this number is equal to the other object
|
205
|
-
def eq(other)
|
206
|
-
return Sass::Script::Bool.new(false) unless other.is_a?(Sass::Script::Number)
|
207
|
-
this = self
|
208
|
-
begin
|
209
|
-
if unitless?
|
210
|
-
this = this.coerce(other.numerator_units, other.denominator_units)
|
211
|
-
else
|
212
|
-
other = other.coerce(@numerator_units, @denominator_units)
|
213
|
-
end
|
214
|
-
rescue Sass::UnitConversionError
|
215
|
-
return Sass::Script::Bool.new(false)
|
216
|
-
end
|
217
|
-
|
218
|
-
Sass::Script::Bool.new(this.value == other.value)
|
219
|
-
end
|
220
|
-
|
221
|
-
# The SassScript `>` operation.
|
222
|
-
#
|
223
|
-
# @param other [Number] The right-hand side of the operator
|
224
|
-
# @return [Boolean] Whether this number is greater than the other
|
225
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
226
|
-
def gt(other)
|
227
|
-
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
|
228
|
-
operate(other, :>)
|
229
|
-
end
|
230
|
-
|
231
|
-
# The SassScript `>=` operation.
|
232
|
-
#
|
233
|
-
# @param other [Number] The right-hand side of the operator
|
234
|
-
# @return [Boolean] Whether this number is greater than or equal to the other
|
235
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
236
|
-
def gte(other)
|
237
|
-
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
|
238
|
-
operate(other, :>=)
|
239
|
-
end
|
240
|
-
|
241
|
-
# The SassScript `<` operation.
|
242
|
-
#
|
243
|
-
# @param other [Number] The right-hand side of the operator
|
244
|
-
# @return [Boolean] Whether this number is less than the other
|
245
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
246
|
-
def lt(other)
|
247
|
-
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
|
248
|
-
operate(other, :<)
|
249
|
-
end
|
250
|
-
|
251
|
-
# The SassScript `<=` operation.
|
252
|
-
#
|
253
|
-
# @param other [Number] The right-hand side of the operator
|
254
|
-
# @return [Boolean] Whether this number is less than or equal to the other
|
255
|
-
# @raise [NoMethodError] if `other` is an invalid type
|
256
|
-
def lte(other)
|
257
|
-
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
|
258
|
-
operate(other, :<=)
|
259
|
-
end
|
260
|
-
|
261
|
-
# @return [String] The CSS representation of this number
|
262
|
-
# @raise [Sass::SyntaxError] if this number has units that can't be used in CSS
|
263
|
-
# (e.g. `px*in`)
|
264
|
-
def to_s(opts = {})
|
265
|
-
return original if original
|
266
|
-
raise Sass::SyntaxError.new("#{inspect} isn't a valid CSS value.") unless legal_units?
|
267
|
-
inspect
|
268
|
-
end
|
269
|
-
|
270
|
-
# Returns a readable representation of this number.
|
271
|
-
#
|
272
|
-
# This representation is valid CSS (and valid SassScript)
|
273
|
-
# as long as there is only one unit.
|
274
|
-
#
|
275
|
-
# @return [String] The representation
|
276
|
-
def inspect(opts = {})
|
277
|
-
value = self.class.round(self.value)
|
278
|
-
unitless? ? value.to_s : "#{value}#{unit_str}"
|
279
|
-
end
|
280
|
-
alias_method :to_sass, :inspect
|
281
|
-
|
282
|
-
# @return [Fixnum] The integer value of the number
|
283
|
-
# @raise [Sass::SyntaxError] if the number isn't an integer
|
284
|
-
def to_i
|
285
|
-
super unless int?
|
286
|
-
return value
|
287
|
-
end
|
288
|
-
|
289
|
-
# @return [Boolean] Whether or not this number is an integer.
|
290
|
-
def int?
|
291
|
-
value % 1 == 0.0
|
292
|
-
end
|
293
|
-
|
294
|
-
# @return [Boolean] Whether or not this number has no units.
|
295
|
-
def unitless?
|
296
|
-
@numerator_units.empty? && @denominator_units.empty?
|
297
|
-
end
|
298
|
-
|
299
|
-
# @return [Boolean] Whether or not this number has units that can be represented in CSS
|
300
|
-
# (that is, zero or one \{#numerator\_units}).
|
301
|
-
def legal_units?
|
302
|
-
(@numerator_units.empty? || @numerator_units.size == 1) && @denominator_units.empty?
|
303
|
-
end
|
304
|
-
|
305
|
-
# Returns this number converted to other units.
|
306
|
-
# The conversion takes into account the relationship between e.g. mm and cm,
|
307
|
-
# as well as between e.g. in and cm.
|
308
|
-
#
|
309
|
-
# If this number has no units, it will simply return itself
|
310
|
-
# with the given units.
|
311
|
-
#
|
312
|
-
# An incompatible coercion, e.g. between px and cm, will raise an error.
|
313
|
-
#
|
314
|
-
# @param num_units [Array<String>] The numerator units to coerce this number into.
|
315
|
-
# See {\#numerator\_units}
|
316
|
-
# @param den_units [Array<String>] The denominator units to coerce this number into.
|
317
|
-
# See {\#denominator\_units}
|
318
|
-
# @return [Number] The number with the new units
|
319
|
-
# @raise [Sass::UnitConversionError] if the given units are incompatible with the number's
|
320
|
-
# current units
|
321
|
-
def coerce(num_units, den_units)
|
322
|
-
Number.new(if unitless?
|
323
|
-
self.value
|
324
|
-
else
|
325
|
-
self.value * coercion_factor(@numerator_units, num_units) /
|
326
|
-
coercion_factor(@denominator_units, den_units)
|
327
|
-
end, num_units, den_units)
|
328
|
-
end
|
329
|
-
|
330
|
-
# @param other [Number] A number to decide if it can be compared with this number.
|
331
|
-
# @return [Boolean] Whether or not this number can be compared with the other.
|
332
|
-
def comparable_to?(other)
|
333
|
-
begin
|
334
|
-
operate(other, :+)
|
335
|
-
true
|
336
|
-
rescue Sass::UnitConversionError
|
337
|
-
false
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
# Returns a human readable representation of the units in this number.
|
342
|
-
# For complex units this takes the form of:
|
343
|
-
# numerator_unit1 * numerator_unit2 / denominator_unit1 * denominator_unit2
|
344
|
-
# @return [String] a string that represents the units in this number
|
345
|
-
def unit_str
|
346
|
-
rv = @numerator_units.sort.join("*")
|
347
|
-
if @denominator_units.any?
|
348
|
-
rv << "/"
|
349
|
-
rv << @denominator_units.sort.join("*")
|
350
|
-
end
|
351
|
-
rv
|
352
|
-
end
|
353
|
-
|
354
|
-
private
|
355
|
-
|
356
|
-
# @private
|
357
|
-
def self.round(num)
|
358
|
-
if num.is_a?(Float) && (num.infinite? || num.nan?)
|
359
|
-
num
|
360
|
-
elsif num % 1 == 0.0
|
361
|
-
num.to_i
|
362
|
-
else
|
363
|
-
(num * self.precision_factor).round / self.precision_factor
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
OPERATIONS = [:+, :-, :<=, :<, :>, :>=]
|
368
|
-
|
369
|
-
def operate(other, operation)
|
370
|
-
this = self
|
371
|
-
if OPERATIONS.include?(operation)
|
372
|
-
if unitless?
|
373
|
-
this = this.coerce(other.numerator_units, other.denominator_units)
|
374
|
-
else
|
375
|
-
other = other.coerce(@numerator_units, @denominator_units)
|
376
|
-
end
|
377
|
-
end
|
378
|
-
# avoid integer division
|
379
|
-
value = (:/ == operation) ? this.value.to_f : this.value
|
380
|
-
result = value.send(operation, other.value)
|
381
|
-
|
382
|
-
if result.is_a?(Numeric)
|
383
|
-
Number.new(result, *compute_units(this, other, operation))
|
384
|
-
else # Boolean op
|
385
|
-
Bool.new(result)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
def coercion_factor(from_units, to_units)
|
390
|
-
# get a list of unmatched units
|
391
|
-
from_units, to_units = sans_common_units(from_units, to_units)
|
392
|
-
|
393
|
-
if from_units.size != to_units.size || !convertable?(from_units | to_units)
|
394
|
-
raise Sass::UnitConversionError.new("Incompatible units: '#{from_units.join('*')}' and '#{to_units.join('*')}'.")
|
395
|
-
end
|
396
|
-
|
397
|
-
from_units.zip(to_units).inject(1) {|m,p| m * conversion_factor(p[0], p[1]) }
|
398
|
-
end
|
399
|
-
|
400
|
-
def compute_units(this, other, operation)
|
401
|
-
case operation
|
402
|
-
when :*
|
403
|
-
[this.numerator_units + other.numerator_units, this.denominator_units + other.denominator_units]
|
404
|
-
when :/
|
405
|
-
[this.numerator_units + other.denominator_units, this.denominator_units + other.numerator_units]
|
406
|
-
else
|
407
|
-
[this.numerator_units, this.denominator_units]
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
def normalize!
|
412
|
-
return if unitless?
|
413
|
-
@numerator_units, @denominator_units = sans_common_units(@numerator_units, @denominator_units)
|
414
|
-
|
415
|
-
@denominator_units.each_with_index do |d, i|
|
416
|
-
if convertable?(d) && (u = @numerator_units.detect(&method(:convertable?)))
|
417
|
-
@value /= conversion_factor(d, u)
|
418
|
-
@denominator_units.delete_at(i)
|
419
|
-
@numerator_units.delete_at(@numerator_units.index(u))
|
420
|
-
end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
# A hash of unit names to their index in the conversion table
|
425
|
-
CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4}
|
426
|
-
CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 ], # in
|
427
|
-
[ nil, 1, 2.36220473, 10, 28.3464567], # cm
|
428
|
-
[ nil, nil, 1, 4.23333333, 12 ], # pc
|
429
|
-
[ nil, nil, nil, 1, 2.83464567], # mm
|
430
|
-
[ nil, nil, nil, nil, 1 ]] # pt
|
431
|
-
|
432
|
-
def conversion_factor(from_unit, to_unit)
|
433
|
-
res = CONVERSION_TABLE[CONVERTABLE_UNITS[from_unit]][CONVERTABLE_UNITS[to_unit]]
|
434
|
-
return 1.0 / conversion_factor(to_unit, from_unit) if res.nil?
|
435
|
-
res
|
436
|
-
end
|
437
|
-
|
438
|
-
def convertable?(units)
|
439
|
-
Array(units).all? {|u| CONVERTABLE_UNITS.include?(u)}
|
440
|
-
end
|
441
|
-
|
442
|
-
def sans_common_units(units1, units2)
|
443
|
-
units2 = units2.dup
|
444
|
-
# Can't just use -, because we want px*px to coerce properly to px*mm
|
445
|
-
return units1.map do |u|
|
446
|
-
next u unless j = units2.index(u)
|
447
|
-
units2.delete_at(j)
|
448
|
-
nil
|
449
|
-
end.compact, units2
|
450
|
-
end
|
451
|
-
end
|
452
|
-
end
|