sassy-escape 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODg4ZjMzZjljMzNjYjI4YzhhZjEyMDU2OWE2NmYwMzI1OWI2MjYzYw==
5
+ data.tar.gz: !binary |-
6
+ YTg0M2EyZGFlZTM1ODE0M2JmMzQyYTgzMzBiYjUyYzBmNGVlODY1Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzI3YWRkNTgwNzEwN2UwNWJkOWVhYTVlNjdlNTJlNWI1YTMyM2M3MDk4Mjc0
10
+ ZTYwYmExZDBhMGZmYzg2ZTcyNDg4ZGNiZGE2NzA0OTY4NjJhNjNjYWIyZWI3
11
+ NjQ2YTNjOTUxZDA5NmYyMjQ4M2NiODA1MzY1NzZiOTk1ODM1NzQ=
12
+ data.tar.gz: !binary |-
13
+ NmJjOWNlNWM3YmM3NTExZWM0NDJiZjMzZjFkMzY3NmYxN2RhMTY4YTU4MzQ5
14
+ MTE4YTQzMDc2NzkzMjI1Y2RjOGMzNzBmNTg4MjVhNDg4OGI2MjkzMTVjODRj
15
+ MmRmZmIwNDkyOTc1NjJhM2E2YzRlZDRhMTRiZTZkZjExZDNjMjY=
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sassy-escape.gemspec
4
+ gemspec
@@ -0,0 +1,64 @@
1
+ Sassy Escape [![Build Status](https://travis-ci.org/borodean/sassy-escape.svg?branch=develop)](https://travis-ci.org/borodean/sassy-escape)
2
+ ============
3
+
4
+ A Sass wrapper for [cssesc,](http://github.com/mathiasbynens/cssesc) a JavaScript library [for escaping text for use in CSS strings or identifiers.](http://mathiasbynens.be/notes/css-escapes)
5
+
6
+ `escape($value, $options...)`
7
+ -----------------------------------
8
+
9
+ This function takes a value and returns an escaped version of the value where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) [escape sequences for use in CSS strings or identifiers.](http://mathiasbynens.be/notes/css-escapes)
10
+
11
+ ```scss
12
+ body::after {
13
+ content: escape('Ich ♥ Bücher');
14
+ }
15
+
16
+ // Becomes this:
17
+ body::after {
18
+ content: 'Ich \2665 B\FC cher';
19
+ }
20
+ ```
21
+
22
+ By default, `escape` returns a string that can be used as part of a CSS string. If the target is a CSS identifier rather than a CSS string, use the `$is-identifier: true` setting.
23
+
24
+ ```scss
25
+ .#{ unquote(escape('123a2b', $is-identifier: true)) } {
26
+ color: red;
27
+ }
28
+
29
+ // Becomes this:
30
+ .\31 23ab {
31
+ color: red;
32
+ }
33
+ ```
34
+
35
+ The optional keyword arguments accept the exact options which JavaScript version [cssesc uses](http://github.com/mathiasbynens/cssesc#api) only converted to the `dasherized-case`:
36
+
37
+ ```scss
38
+ body::after {
39
+ content: escape('123a2b', $escape-everything: true, $quotes: 'single', $wrap: true);
40
+ }
41
+ ```
42
+
43
+ Installation
44
+ ------------
45
+
46
+ ```bash
47
+ gem install sassy-escape
48
+ ```
49
+
50
+ Use with Sass command line
51
+ --------------------------
52
+
53
+ ```bash
54
+ sass -r sassy-escape --watch sass_dir:css_dir
55
+ ```
56
+
57
+ Use with Compass
58
+ ----------------
59
+
60
+ Add the following to your Compass configuration:
61
+
62
+ ```ruby
63
+ require 'sass-escape'
64
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ require "sass"
2
+ require "sassy-escape/version"
3
+
4
+ module Sass::Script::Functions
5
+ # Return a string containing the escaped version of the provided data for
6
+ # use as a CSS identifier
7
+ def escape(data, options = {})
8
+ require "cssesc"
9
+ if data.instance_of? Sass::Script::String
10
+ string = data.value.to_s
11
+ type = data.type
12
+ else
13
+ string = data.to_s
14
+ type = :identifier
15
+ end
16
+ options.each_pair { |k, v| options[k] = v.value }
17
+ escaped_string = CSSEsc.escape(string, options)
18
+ Sass::Script::String.new(escaped_string, type)
19
+ end
20
+
21
+ Sass::Script::Functions.declare :escape, [:data], var_kwargs: true
22
+ end
23
+
24
+ module SassyEscape
25
+ VERSION = '0.1.0'
26
+ end
@@ -0,0 +1,3 @@
1
+ module SassyEscape
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sassy-escape/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sassy-escape"
7
+ spec.version = SassyEscape::VERSION
8
+ spec.authors = ["Vadim Borodean"]
9
+ spec.email = ["borodean@gmail.com"]
10
+
11
+ spec.summary = "Sass wrapper for a JavaScript library for escaping CSS strings and identifiers"
12
+ spec.homepage = "http://github.com/borodean/sassy-escape"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "cssesc"
20
+ spec.add_dependency "sass"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "therubyracer"
25
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "sass"
3
+ require "sassy-escape"
4
+
5
+ describe Sass::Script::Functions do
6
+
7
+ def sass(value)
8
+ Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
9
+ end
10
+
11
+ describe "#escape" do
12
+
13
+ it "escapes strings" do
14
+ expect(sass(%q{escape('Ich ♥ Bücher')}))
15
+ .to eq(%q{"Ich \\\\2665 B\\\\FC cher"})
16
+ end
17
+
18
+ it "preverves identifiers" do
19
+ expect(sass("escape(foo)"))
20
+ .to eq("foo")
21
+ end
22
+
23
+ it "accepts options" do
24
+ expect(sass(%q{escape('lolwat"foo\'bar', $escape-everything: true)}))
25
+ .to eq(%q{"\\\\6C\\\\6F\\\\6C\\\\77\\\\61\\\\74\\\\\\"\\\\66\\\\6F\\\\6F\\\\'\\\\62\\\\61\\\\72"})
26
+ end
27
+
28
+ it "accepts falsy options" do
29
+ expect(sass(%q{escape('lolwat"foo\'bar', $escape-everything: false)}))
30
+ .to eq(%q{"lolwat\"foo\\\\'bar"})
31
+ end
32
+
33
+ it "escape numbers" do
34
+ expect(sass("escape(10px, $is-identifier: true)"))
35
+ .to eq("\\31 0px")
36
+ end
37
+
38
+ it "properly unquotes" do
39
+ expect(sass("unquote(escape('+1', $is-identifier: true))"))
40
+ .to eq("\\+1")
41
+ end
42
+
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sassy-escape
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vadim Borodean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cssesc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sass
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: therubyracer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - borodean@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - lib/sassy-escape.rb
111
+ - lib/sassy-escape/version.rb
112
+ - sassy-escape.gemspec
113
+ - spec/sassy_escape_spec.rb
114
+ homepage: http://github.com/borodean/sassy-escape
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.6
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Sass wrapper for a JavaScript library for escaping CSS strings and identifiers
138
+ test_files:
139
+ - spec/sassy_escape_spec.rb