pax_global_header00006660000000000000000000000064123433602230014510gustar00rootroot0000000000000052 comment=2cd2d0ed7a0c0f0b68dc1ef621548dc7ada3efec Sassy-Maps-0.4.0/000077500000000000000000000000001234336022300135115ustar00rootroot00000000000000Sassy-Maps-0.4.0/.bowerrc000066400000000000000000000000421234336022300151510ustar00rootroot00000000000000{ "directory": "components" } Sassy-Maps-0.4.0/.bundle/000077500000000000000000000000001234336022300150405ustar00rootroot00000000000000Sassy-Maps-0.4.0/.bundle/config000066400000000000000000000000701234336022300162250ustar00rootroot00000000000000--- BUNDLE_PATH: vendor BUNDLE_DISABLE_SHARED_GEMS: '1' Sassy-Maps-0.4.0/.editorconfig000066400000000000000000000006371234336022300161740ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] # Change these settings to your own preference indent_style = space indent_size = 2 # We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false Sassy-Maps-0.4.0/.gitattributes000066400000000000000000000000131234336022300163760ustar00rootroot00000000000000* text=autoSassy-Maps-0.4.0/.gitignore000066400000000000000000000001441234336022300155000ustar00rootroot00000000000000node_modules /components .www .sass-cache Gemfile.lock export *.gem /vendor /tests/output/**/*.diff Sassy-Maps-0.4.0/.travis.yml000066400000000000000000000001331234336022300156170ustar00rootroot00000000000000language: ruby rvm: - 2.0.0 - 2.1.1 gemfile: - Gemfile branches: only: - 0.x.x Sassy-Maps-0.4.0/CONTRIBUTING.md000066400000000000000000000023171234336022300157450ustar00rootroot00000000000000## Contributing to Sassy Maps We love contributors! Yes we do! If you would like to contribute to Sassy Maps, please follow the following guidelines: * **DO NOT ISSUE A PULL REQUEST WITHOUT RELATED ISSUE!!** All pull requests must reference an issue in the issue queue and will only be looked at after discussion about that issue has taken place. Any pull request created that does not reference an issue will be closed. * Each individual feature you would like add, or bug you would like to squash, should be an individual pull request. Each pull request should be from an individual feature branch to either the latest stable or development branch. **The current *stable* branch is 0.x.x. The current *development* branch is 0.x.x**. Contributions that are not in the form of a pull request will not be considered. If your pull request does not apply cleanly we will ask you to fix that before we will look into pulling it in. We may ask you to update or make changes to the code you've submitted, please don't take this the wrong way. If a pull request smells (such as if a large amount of code is all within a single commit, or the coding standards aren't in line with core Singularity) we may ask you to rewrite your commit.Sassy-Maps-0.4.0/Gemfile000066400000000000000000000000471234336022300150050ustar00rootroot00000000000000source 'https://rubygems.org' gemspec Sassy-Maps-0.4.0/README.md000066400000000000000000000121621234336022300147720ustar00rootroot00000000000000# Sassy Maps [![Gem Version](https://badge.fury.io/rb/sassy-maps.png)](http://badge.fury.io/rb/sassy-maps) [![Build Status](https://travis-ci.org/Team-Sass/Sassy-Maps.png?branch=0.x.x)](https://travis-ci.org/Team-Sass/Sassy-Maps) Sassy Maps adds a variety of functions aimed at helping you work with Sass 3.3 maps much easier. ## Table of Contents 1. [Requirements](#requirements) 2. [Installation](#installation) 3. [Using Sassy Maps](#using-sassy-maps) 4. [Functions](#functions) 5. [Optional Modules](#optional-modules) * [Memo](#memo) ## Requirements Sassy Maps is a Sass extension, so you're going to need Sass installed. If you do not already have Sass installed, please read [Install Sass](http://sass-lang.com/install). Sassy Maps 0.3.x requires *Sass 3.3.0* or higher. **It is HIGHLY RECOMMENDED that you run all Sass (or Compass if using it) commands through [Bundler](http://bundler.io/)** If the compiler you are using is not compatible with the above minimum versions, it will not compile correctly. **BE AWARE that CodeKit and most other GUI compilers *do not support Bundler* and are therefore NOT RECOMMENDED** ## Installation The preferred way to install and use Sassy Maps is through Bundler. To do so, add the following to your Gemfile (Sass provided to ensure the correct versions are used): ```ruby gem "sass", "~>3.3.0" gem "sassy-maps", "~>0.3.2" ``` Once you have done so, run `bundle install` to install your dependencies, and remember to run all of your compilation through `bundle exec`. You can also install Sassy Maps through [Bower](http://bower.io/) as it has no Ruby requirements. To do so, run the following command: ```bash bower install sassy-maps --save-dev ``` *BE AWARE* that while you can install Sassy Maps through Bower, Sassy Maps still only works with Sass compilers that have full compatibility with Sass 3.3.x and greater. If using Compass, you are also going to need to add the folder using Compass's [`add_import_path`](http://compass-style.org/help/tutorials/configuration-reference/) config option instead of the standard `require`. ## Using Sassy Maps If you already have a project made and you'd like to use Sassy Maps with it, add the following to your `config.rb` file: `require 'sassy-maps'` Then, add the following to your Sass file towards the top: `@import "sassy-maps";` ## Functions * `map-get-deep($map, $keys...)` - Returns the value of the final item in `$keys` from the map `$map`. Will return `null` if no value is present and will warn of errors in search (such as if an intermediate depth is `null` or not a `map`). * `map-set($map, $key, $value)` - Returns a map that has the `$key` in `$map` set to the to given `$value`. * `map-set-deep($map, $keys, $value)` - Returns a map that has the `$key` in `$map` set to the given `$value`. `$key` should be single-depth list of keys, for instance `map-set-deep($map, ('foo' 'bar' 'baz'), "Hello World")`. * `map-to-string($map)` - Returns a string representation of the given `$map`. ## Optional Modules Sassy Maps comes with optional modules that extend upon the base functionality of Sassy Maps to provide additional map-based functionality. The following are optional modules available with Sassy Maps: * [Memo](#memo) ### Memo Memo is a [Memoization](http://en.wikipedia.org/wiki/Memoization) framework for Sass. Designed with framework developers in mind, it makes it easy to store and retrieve the output of functions quickly and easily without needing to run the function again. For complex functions this should greatly speed up overall compilation time for repeat function calls with identical input. To use Memo, simply include `@import "memo";` and you're good to go (normal [Sassy Maps installation](#installation) still applies). Memo comes with two functions: * `memo-set($module, $key, $value)` - Sets a memoization `$key` to the given `$value` for the prescribed `$module` (framework). The function will return `true`. Also available as a mixin (`@include memo-set($module, $key, $value)`). * `memo-get($module, $key)` - Returns the value of the memoization `$key` for the prescribed `$module`. Using Memo is fairly simple, just check to see if there is a memoization value for your key (and it's not `null`); if there is, return that, if not, run through the function, set the memoization, and return that result. The following example stores whether Memo is available in a variable and uses the function name as the memoization module, but if building a framework such as [Breakpoint](http://github.com/team-sass/breakpoint), that framework should be the name of the memoization module. ```scss $Memo-Exists: function-exists(memo-get) and function-exists(memo-set); @function percentage($target, $context) { @if $Memo-Exists { $result: memo-get(percentage, $target $context); @if $result != null { @return $result; } } $result: $target / $context * 100%; @if $Memo-Exists { $holder: memo-set(percentage, $target $context, $result); } @return $result; } $half: percentage(20px, 40px); // No memoization exists, will run through the function $half-again: percentage(20px, 40px); // Memoization exists, will just return that result ``` Sassy-Maps-0.4.0/Rakefile000066400000000000000000000012111234336022300151510ustar00rootroot00000000000000require 'bundler/gem_tasks' require 'rake/testtask' Rake::TestTask.new do |t| t.libs = ['lib','tests'] t.test_files = Dir.glob('tests/**/*_test.rb').sort t.verbose = false t.options = "- --tapy | tapout navigator --require tapout/reporters/navigator_reporter" end task :default => :test desc 'Re-render all test Sass files to new control files.' task 'render' => ['environment'] do require File.expand_path('../tests/navigator', __FILE__) Navigator::Renderer.render_controls end task 'environment' do lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'sassy-maps' end Sassy-Maps-0.4.0/bower.json000066400000000000000000000005651234336022300155300ustar00rootroot00000000000000{ "name": "sassy-maps", "version": "0.4.0", "authors": [ "Sam Richard " ], "main": "sass/_sassy-maps.scss", "devDependencies": {}, "ignore": [ "**/.*", "node_modules", "bower_components", "components", "tests", "Gemfile", "images", "fonts", "js", "package.json", "config.*", "*.gem" ] } Sassy-Maps-0.4.0/examples/000077500000000000000000000000001234336022300153275ustar00rootroot00000000000000Sassy-Maps-0.4.0/examples/example.scss000066400000000000000000000023761234336022300176670ustar00rootroot00000000000000@import "sassy-maps"; $map: (400: "value", "key2": "value2", "key3": ("foo": "bar", "baz": ("waldo": "qux"), 'steve': 'perry'), "bob": "george"); // @debug $map; $string: inspect($map); // @debug type-of($string); // @debug $string; $map: map-set($map, 'key2', 'value3'); // @debug $map; @debug map-get-deep($map, 'key4', 'nine', 'eight'); @debug $map; $map: map-set-deep($map, ('key3' 'baz' 'waldo'), "molly"); $map: map-set-deep($map, ('key3' 'baz' 'qux'), 'quark'); $map: map-set-deep($map, ('key3' 'jedi' 'vader'), 'red'); $map: map-set-deep($map, ('key3' 'jedi' 'luke'), 'green'); $map: map-set-deep($map, ('key4' 'nine' 'eight'), 'seven'); @debug $map; @import "memo"; @include memo-set(singularity, 2 .75 split, 50%); @include memo-set(singularity, 2 .5 split, 75%); @import "memo"; $memo-exists: function-exists(memo-get) and function-exists(memo-set); @function percentage($target, $context) { $result: memo-get(percentage, $target $context); @if not ($memo-exists and $result != null) { $result: $target / $context * 100%; $holder: memo-set(percentage, $target $context, $result); } @return $result; } $half: percentage(20px, 40px); $half-again: percentage(20px, 40px); @debug $Memoization-Table; @debug memo-get(singularity, 2 .75 split);Sassy-Maps-0.4.0/examples/index.html000066400000000000000000000014761234336022300173340ustar00rootroot00000000000000 Example

Sassy Maps In Action

Sassy-Maps-0.4.0/lib/000077500000000000000000000000001234336022300142575ustar00rootroot00000000000000Sassy-Maps-0.4.0/lib/sassy-maps.rb000066400000000000000000000005361234336022300167100ustar00rootroot00000000000000require 'sassy-maps/version' require 'sass' sassy_maps_path = File.expand_path('../../sass', __FILE__) if (defined? Compass) Compass::Frameworks.register( 'sassy-maps', :stylesheets_directory => sassy_maps_path ) else ENV["SASS_PATH"] = [ENV["SASS_PATH"], sassy_maps_path].compact.join(File::PATH_SEPARATOR) end module SassyMaps end Sassy-Maps-0.4.0/lib/sassy-maps/000077500000000000000000000000001234336022300163575ustar00rootroot00000000000000Sassy-Maps-0.4.0/lib/sassy-maps/version.rb000066400000000000000000000000771234336022300203750ustar00rootroot00000000000000module SassyMaps VERSION = "0.4.0" DATE = "2014-06-03" end Sassy-Maps-0.4.0/lib/tapout/000077500000000000000000000000001234336022300155735ustar00rootroot00000000000000Sassy-Maps-0.4.0/lib/tapout/reporters/000077500000000000000000000000001234336022300176205ustar00rootroot00000000000000Sassy-Maps-0.4.0/lib/tapout/reporters/navigator_reporter.rb000066400000000000000000000004251234336022300240620ustar00rootroot00000000000000require 'tapout' require 'tapout/reporters' module Tapout module Reporters class NavigatorReporter < RuntimeReporter def backtrace_snippets(test) '' end end end end Tapout::Reporters.index['navigator'] = Tapout::Reporters::NavigatorReporter Sassy-Maps-0.4.0/package.json000066400000000000000000000001611234336022300157750ustar00rootroot00000000000000{ "name": "sassy-maps", "version": "0.3.2", "dependencies": {}, "engines": { "node": ">=0.8.0" } } Sassy-Maps-0.4.0/sache.json000066400000000000000000000003411234336022300154650ustar00rootroot00000000000000{ "name": "sassy-maps", "description": "Sassy Maps adds a variety of functions aimed at helping you work with Sass 3.3 maps much easier.", "tags": ["maps", "dry", "performance", "code-quality", "memo", "memoization"] } Sassy-Maps-0.4.0/sass/000077500000000000000000000000001234336022300144625ustar00rootroot00000000000000Sassy-Maps-0.4.0/sass/_memo.scss000066400000000000000000000014101234336022300164470ustar00rootroot00000000000000@import "sassy-maps"; $Memoization-Table: () !default; ////////////////////////////// // Memoization Set ////////////////////////////// @function memo-set($module, $key, $value) { $module: "#{$module}"; $key: "#{$key}"; $Memoization-Table: map-set-deep($Memoization-Table, ($module $key), $value) !global; @return true; } @mixin memo-set($module, $key, $value) { $holder: memo-set($module, $key, $value); } ////////////////////////////// // Memoization Get ////////////////////////////// @function memo-get($module, $key) { $module: "#{$module}"; $key: "#{$key}"; $private-sassy-maps-suppress-warnings: true !global; $result: map-get-deep($Memoization-Table, $module, $key); $private-sassy-maps-suppress-warnings: false !global; @return $result; } Sassy-Maps-0.4.0/sass/_sassy-maps.scss000066400000000000000000000005161234336022300176200ustar00rootroot00000000000000////////////////////////////// // To String ////////////////////////////// @import "sassy-maps/map-to-string"; ////////////////////////////// // Getting Helpers ////////////////////////////// @import "sassy-maps/map-get"; ////////////////////////////// // Setting Helpers ////////////////////////////// @import "sassy-maps/map-set";Sassy-Maps-0.4.0/sass/sassy-maps/000077500000000000000000000000001234336022300165625ustar00rootroot00000000000000Sassy-Maps-0.4.0/sass/sassy-maps/_map-get.scss000066400000000000000000000024171234336022300211540ustar00rootroot00000000000000$private-sassy-maps-suppress-warnings: false !default; ////////////////////////////// // Map Get Deep // // Given a map and a list of keys, find the value at the given key ////////////////////////////// @function map-get-deep($map, $keys...) { @if length($keys) == 1 { $keys: nth($keys, 1); } $warn: "#{nth($keys, 1)}"; $length: length($keys); $get: map-get($map, nth($keys, 1)); @if $length > 1 { @for $i from 2 through $length { @if $get != null and type-of($get) == 'map' { $warn: $warn + "->#{nth($keys, $i)}"; $get: map-get($get, nth($keys, $i)); @if $get == null { @return map-get-deep-warning($warn, $get); } } @else { @return map-get-deep-warning($warn, $get); } } } @return $get; } ////////////////////////////// // Map Get Deep Warning // // Displays a warning if the retrieved value is `null` ////////////////////////////// @function map-get-deep-warning($warn, $get) { @if not $private-sassy-maps-suppress-warnings { @if $get == null { @warn "Map has no value for key search `#{$warn}`"; } @else if type-of($get) != 'map' { @warn "Non-map value found for key search `#{$warn}`, cannot search for key `#{nth($keys, $i)}`"; } } @return null; } Sassy-Maps-0.4.0/sass/sassy-maps/_map-set.scss000066400000000000000000000022051234336022300211630ustar00rootroot00000000000000@function get-keys($keys, $counter) { $return: (); @for $i from 1 to $counter { $return: append($return, nth($keys, $i)); } @return $return; } @function map-set($map, $key, $value) { @return map-merge($map, ($key: $value)); } @function map-set-deep($map, $keys, $value) { $private-sassy-maps-suppress-warnings: true !global; $length: length($keys); $get-keys: (); $map-level: (); @if $length > 1 { $get-keys: get-keys($keys, $length); $map-level: map-get-deep($map, $get-keys); } $merge: (nth($keys, $length): $value); @if $map-level { $merge: map-merge($map-level, $merge); } @for $i from ($length * -1 + 1) through -1 { $j: abs($i); $key: nth($keys, $j); // // @debug $get-keys; @if $j > 1 { $get-keys: get-keys($keys, $j); $map-level: map-get-deep($map, $get-keys); @if $map-level { $merge: map-merge($map-level, ($key: $merge)); } @else { $merge: ($key: $merge); } } @else { $merge: ($key: $merge); } } $map: map-merge($map, $merge); $private-sassy-maps-suppress-warnings: false !global; @return $map; } Sassy-Maps-0.4.0/sass/sassy-maps/_map-to-string.scss000066400000000000000000000000721234336022300223160ustar00rootroot00000000000000@function map-to-string($map) { @return inspect($map); }Sassy-Maps-0.4.0/sassy-maps.gemspec000066400000000000000000000021031234336022300171520ustar00rootroot00000000000000$:.push File.expand_path('../lib', __FILE__) require 'sassy-maps/version' Gem::Specification.new do |s| s.name = 'sassy-maps' s.version = SassyMaps::VERSION s.platform = Gem::Platform::RUBY s.authors = ['Sam Richard'] s.email = ['sam@snug.ug'] s.license = 'MIT' s.homepage = 'https://github.com/Snugug/Sassy-Maps' s.summary = 'Map helper functions for Sass 3.3 Maps' s.description = 'Map helper functions for Sass 3.3 Maps including get-deep and set/set-deep' s.rubyforge_project = 'sassy-maps' s.files = ['README.md'] s.files += Dir.glob("lib/**/*.*") s.files += Dir.glob("sass/**/*.*") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_paths = ["lib"] s.add_dependency('sass', '~> 3.3') s.add_development_dependency('bundler') s.add_development_dependency('rake') s.add_development_dependency('minitest') s.add_development_dependency('minitap') s.add_development_dependency('tapout') s.add_development_dependency('term-ansicolor') s.add_development_dependency('colorize') end Sassy-Maps-0.4.0/tests/000077500000000000000000000000001234336022300146535ustar00rootroot00000000000000Sassy-Maps-0.4.0/tests/README.md000066400000000000000000000032251234336022300161340ustar00rootroot00000000000000Place your test SCSS files in here. These files will be compiled into an `output` directory and those output files will be compared against our `controls`. If there is a difference, you will get a a diff of your `output` vs your `controls`. Each individual piece you're testing, from a function to a mixin to general usage, should be easy to identify what it is from the output CSS. The general convention to follow is something like the following: ```scss ////////////////////////////// // Functions ////////////////////////////// /** * Function Name Function **/ .function-name { /* Each permutation of input/output that is possible should get a CSS comment */ /* No Defaulted Input */ _test: "function-name(input)"; _result: function-name(input); /* Defaulted Input */ _test: "function-name(input, input2)"; _result: function-name(input, input2); } ////////////////////////////// // Mixins ////////////////////////////// /** * Mixin Name **/ .mixin-name { /* Each permutation of input/output that is possible should get a CSS comment */ /* No Defaulted Input */ _test: "mixin-name(input)" @include mixin-name(input); /* Defaulted Input */ _test: "mixin-name(input, input2)" @include mixin-name(input, input2); } ``` You want representative examples of input/output. Don't be afraid to add tests as you need them, the more tests the better! It's very likely that, for complex systems, the total number of tests you write (and their related control) will outweigh your actual Compass framework. You're also encouraged to have multiple files in multiple folders to break down what you're testing into chunks in order to test small, discrete pieces. Sassy-Maps-0.4.0/tests/controls/000077500000000000000000000000001234336022300165165ustar00rootroot00000000000000Sassy-Maps-0.4.0/tests/controls/01-map-get.css000066400000000000000000000015051234336022300210010ustar00rootroot00000000000000/** * Map Get Deep **/ .map { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); } .map-get-deep--single-valid { _test: "map-get-deep($map, 'foo')"; _result: "bar"; } .map-get-deep--single-invalid { _test: "map-get-deep($map, 'bar')"; _result: null; } .map-get-deep--first-valid { _test: "map-get-deep($map, 'baz', 'jedi')"; _result: ("vader": red, "luke": green); } .map-get-deep--first-invalid { _test: "map-get-deep($map, 'baz', 'waldo')"; _result: null; } .map-get-deep--second-valid { _test: "map-get-deep($map, 'baz', 'jedi', 'luke')"; _result: green; } .map-get-deep--second-invalid { _test: "map-get-deep($map, 'baz', 'jedi', 'chewie')"; _result: null; } .map-get-deep--second-invalid { _test: "map-get-deep($map, 'baz', 'waldo', 'luke')"; _result: null; } Sassy-Maps-0.4.0/tests/controls/02-map-set.css000066400000000000000000000033311234336022300210150ustar00rootroot00000000000000/** * Map Set **/ .map-set--existing { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set($map, 'foo', 400)"; _result: ("foo": 400, "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); } .map-set--new { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set($map, 'planets', ('Earth', 'Mars'))"; _result: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green)))), "planets": ("Earth", "Mars")); } /** * Map Set Deep **/ .map-set-deep--first-existing { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set-deep($map, 'baz' 'jedi', ('windu': purple))"; _result: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("windu": purple))))); } .map-set-deep--first-new { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set-deep($map, 'baz' 'Carmen', 'Sandiego')"; _result: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green)), "Carmen": "Sandiego"))); } .map-set-deep--second-existing { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set-deep($map, 'baz' 'jedi' 'luke', ('color': green))"; _result: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": (("color": green))))))); } .map-set-deep--second-new { _map: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green))))); _test: "map-set-deep($map, 'baz' 'jedi' 'windu', purple)"; _result: ("foo": "bar", "baz": (("qux": "waldo", "jedi": (("vader": red, "luke": green, "windu": purple))))); } Sassy-Maps-0.4.0/tests/controls/03-memo.css000066400000000000000000000017041234336022300204070ustar00rootroot00000000000000/** * Memo Mixin **/ .memo--mixin--new { _memo-table: (); _test: "@include memo-set(test, foo, bar)"; _get: "memo-get(test, foo)"; _result: bar; _memo-table: ("test": (("foo": bar))); } .memo--mixin--existing { _memo-table: ("test": (("foo": bar))); _test: "@include memo-set(test, foo, qux)"; _get: "memo-get(test, foo)"; _result: qux; _memo-table: ("test": (("foo": qux))); } .memo--function--new { _memo-table: ("test": (("foo": qux))); _test: "$holder: memo-set(test, baz, waldo)"; _get: "memo-get(test, baz)"; _result: waldo; _memo-table: ("test": (("foo": qux, "baz": waldo))); } .memo--function--existing { _memo-table: ("test": (("foo": qux, "baz": waldo))); _test: "$holder: memo-set(test, baz, ('jedi': ('vader': red, 'luke': green)))"; _get: "memo-get(test, baz)"; _result: ("jedi": (("vader": red, "luke": green))); _memo-table: ("test": (("foo": qux, "baz": (("jedi": (("vader": red, "luke": green))))))); } Sassy-Maps-0.4.0/tests/navigator.rb000066400000000000000000000057331234336022300172020ustar00rootroot00000000000000require 'colorize' require 'term/ansicolor' require 'minitap' require 'tapout' Minitest.reporter = Minitap::TapY module Navigator def self.create_tests(test_klass) test_names.each do |file_name| tn = file_name.tr '/', '_' test_klass.instance_eval do define_method(:"test_#{tn}") { assert_rendered_file(file_name) } end end end def self.test_names @test_files ||= Dir["#{tests_root}/tests/**/*.{scss}"].map do |file| file.sub("#{tests_root}/tests/", '').sub(/\.scss/, '') end end def self.tests_root @tests_root ||= File.expand_path File.join(File.dirname(__FILE__)) end def self.tests_output_dir @tests_output_dir ||= File.join Navigator.tests_root, 'output' end def self.tests_output_dir_clean! Dir["#{Navigator.tests_output_dir}/**/*.{diff}"].each { |f| File.delete(f) } end def self.tests_sass_file(file_name) File.join Navigator.tests_root, 'tests', "#{file_name}.scss" end def self.tests_output(file_name) file = File.join Navigator.tests_root, 'output', "#{file_name}.css.diff" # file = File.join Navigator.tests_output_dir, "#{file_name}.css.diff" FileUtils.mkdir_p(File.dirname(file)) file end def self.tests_control_file(file_name) File.join Navigator.tests_root, 'controls', "#{file_name}.css" end class Renderer attr_reader :file_name class << self def render_sass_file(file_name) self.new(file_name).render end def render_controls Navigator.test_names.each do |file_name| control_css = render_sass_file(file_name) control_file = Navigator.tests_control_file(file_name) File.open(control_file,'w') { |f| f.write(control_css) } puts "Rendered->#{control_file}".colorize(:light_cyan) end end end def initialize(file_name) @file_name = file_name end def render options = {:syntax => :scss, :cache => false, :style => :expanded} template = File.read(sass_file) Sass::Engine.new(template, options).render end def sass_file Navigator.tests_sass_file(file_name) end end module Assertions def self.included(base) Navigator.create_tests(base) Navigator.tests_output_dir_clean! end private def assert_rendered_file(file_name) rendered_sass = Navigator::Renderer.render_sass_file(file_name) control_sass = File.read(Navigator.tests_control_file(file_name)) flunk_sass(file_name, control_sass, rendered_sass) if control_sass != rendered_sass end def flunk_sass(file_name, control_sass, rendered_sass) diff_file = Navigator.tests_output(file_name) diff_data = diff(control_sass, rendered_sass) File.open(diff_file,'w') { |f| f.write(diff_data) } msg = "" msg << "Control->Compiled diff output to".colorize(:light_yellow) msg << " #{diff_file}\n".colorize(:light_cyan) msg << `cdiff #{diff_file}`.chomp flunk(msg) end end end Sassy-Maps-0.4.0/tests/output/000077500000000000000000000000001234336022300162135ustar00rootroot00000000000000Sassy-Maps-0.4.0/tests/output/.gitkeey000066400000000000000000000000001234336022300176430ustar00rootroot00000000000000Sassy-Maps-0.4.0/tests/sassy_maps_test.rb000066400000000000000000000003111234336022300204140ustar00rootroot00000000000000require 'bundler' ; Bundler.require :development, :test require 'sassy-maps' require 'navigator' require 'minitest/autorun' class SassyMapsTest < Minitest::Test include Navigator::Assertions end Sassy-Maps-0.4.0/tests/tests/000077500000000000000000000000001234336022300160155ustar00rootroot00000000000000Sassy-Maps-0.4.0/tests/tests/01-map-get.scss000066400000000000000000000023541234336022300204660ustar00rootroot00000000000000$private-sassy-maps-suppress-warnings: true; @import "sassy-maps"; $map: ( "foo": "bar", "baz": ( "qux": "waldo", "jedi": ( "vader": red, "luke": green ) ) ); /** * Map Get Deep **/ .map { _map: inspect($map); } .map-get-deep { &--single { &-valid { _test: "map-get-deep($map, 'foo')"; _result: inspect(map-get-deep($map, 'foo')); } &-invalid { _test: "map-get-deep($map, 'bar')"; _result: inspect(map-get-deep($map, 'bar')); } } &--first { &-valid { _test: "map-get-deep($map, 'baz', 'jedi')"; _result: inspect(map-get-deep($map, 'baz', 'jedi')); } &-invalid { _test: "map-get-deep($map, 'baz', 'waldo')"; _result: inspect(map-get-deep($map, 'baz', 'waldo')); } } &--second { &-valid { _test: "map-get-deep($map, 'baz', 'jedi', 'luke')"; _result: inspect(map-get-deep($map, 'baz', 'jedi', 'luke')); } &-invalid { _test: "map-get-deep($map, 'baz', 'jedi', 'chewie')"; _result: inspect(map-get-deep($map, 'baz', 'jedi', 'chewie')); } &-invalid { _test: "map-get-deep($map, 'baz', 'waldo', 'luke')"; _result: inspect(map-get-deep($map, 'baz', 'jedi', 'chewie')); } } } Sassy-Maps-0.4.0/tests/tests/02-map-set.scss000066400000000000000000000025351234336022300205040ustar00rootroot00000000000000$private-sassy-maps-suppress-warnings: true; @import "sassy-maps"; $map: ( "foo": "bar", "baz": ( "qux": "waldo", "jedi": ( "vader": red, "luke": green ) ) ); /** * Map Set **/ .map-set { &--existing { _map: inspect($map); _test: "map-set($map, 'foo', 400)"; _result: inspect(map-set($map, 'foo', 400)); } &--new { _map: inspect($map); _test: "map-set($map, 'planets', ('Earth', 'Mars'))"; _result: inspect(map-set($map, 'planets', ('Earth', 'Mars'))); } } /** * Map Set Deep **/ .map-set-deep { &--first { &-existing { _map: inspect($map); _test: "map-set-deep($map, 'baz' 'jedi', ('windu': purple))"; _result: inspect(map-set-deep($map, 'baz' 'jedi', ('windu': purple))); } &-new { _map: inspect($map); _test: "map-set-deep($map, 'baz' 'Carmen', 'Sandiego')"; _result: inspect(map-set-deep($map, 'baz' 'Carmen', 'Sandiego')); } } &--second { &-existing { _map: inspect($map); _test: "map-set-deep($map, 'baz' 'jedi' 'luke', ('color': green))"; _result: inspect(map-set-deep($map, 'baz' 'jedi' 'luke', ('color': green))); } &-new { _map: inspect($map); _test: "map-set-deep($map, 'baz' 'jedi' 'windu', purple)"; _result: inspect(map-set-deep($map, 'baz' 'jedi' 'windu', purple)); } } } Sassy-Maps-0.4.0/tests/tests/03-memo.scss000066400000000000000000000023031234336022300200650ustar00rootroot00000000000000@import "memo"; /** * Memo Mixin **/ .memo--mixin { &--new { _memo-table: inspect($Memoization-Table); _test: "@include memo-set(test, foo, bar)"; @include memo-set(test, foo, bar); _get: "memo-get(test, foo)"; _result: memo-get(test, foo); _memo-table: inspect($Memoization-Table); } &--existing { _memo-table: inspect($Memoization-Table); _test: "@include memo-set(test, foo, qux)"; @include memo-set(test, foo, qux); _get: "memo-get(test, foo)"; _result: memo-get(test, foo); _memo-table: inspect($Memoization-Table); } } .memo--function { &--new { _memo-table: inspect($Memoization-Table); _test: "$holder: memo-set(test, baz, waldo)"; $holder: memo-set(test, baz, waldo); _get: "memo-get(test, baz)"; _result: memo-get(test, baz); _memo-table: inspect($Memoization-Table); } &--existing { _memo-table: inspect($Memoization-Table); _test: "$holder: memo-set(test, baz, ('jedi': ('vader': red, 'luke': green)))"; $holder: memo-set(test, baz, ('jedi': ('vader': red, 'luke': green))); _get: "memo-get(test, baz)"; _result: inspect(memo-get(test, baz)); _memo-table: inspect($Memoization-Table); } }