SassyExport 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +56 -0
- data/lib/SassyExport.rb +34 -0
- data/stylesheets/SassyExport.scss +18 -0
- metadata +66 -0
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# SassyExport
|
2
|
+
|
3
|
+
SassyExport is a lightweight plugin for [SassyJSON](https://github.com/HugoGiraudel/SassyJSON) that allows you to export an encoded Sass map into an external JSON file. Use it anyway you like.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. `gem install SassyExport`
|
8
|
+
2. Add `require "SassyExport"` to your `config.rb`
|
9
|
+
3. Import into your stylesheet with `@import "SassyExport";`
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
|
13
|
+
#### Setup
|
14
|
+
```scss
|
15
|
+
// ./sass/SassyExport.scss
|
16
|
+
|
17
|
+
@mixin json_export($path, $filename, $map) {
|
18
|
+
@at-root {
|
19
|
+
%json_export {
|
20
|
+
content: "#{SassyJSON_export(unquote($path), unquote($filename), unquote(json_encode($map)))}";
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
```scss
|
27
|
+
// ./sass/style.scss
|
28
|
+
|
29
|
+
@import "SassyExport";
|
30
|
+
|
31
|
+
$map: (
|
32
|
+
hello: world,
|
33
|
+
);
|
34
|
+
|
35
|
+
@include json_export("../json", "hello", $map);
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Result
|
39
|
+
New JSON file is created in `./json/hello.json`
|
40
|
+
|
41
|
+
```json
|
42
|
+
{"hello": "world"}
|
43
|
+
```
|
44
|
+
|
45
|
+
The `json_export()` mixin takes a directory `$path`, `$filename`, and a Sass `$map` as arguments. It then converts the `$map` into a JSON map with SassyJSON's `json_encode()` function, then Ruby creates a new file (or updates an existing file), and writes the contents of the json string to it. I'm no Ruby expert, so if you belive that you could improve the small amount of code here, feel free to.
|
46
|
+
|
47
|
+
Enjoy.
|
48
|
+
|
49
|
+
## SassyJSON
|
50
|
+
|
51
|
+
* [Download SassyJSON](https://github.com/HugoGiraudel/SassyJSON)
|
52
|
+
|
53
|
+
## Credits
|
54
|
+
|
55
|
+
* [Fabrice Weinberg](http://twitter.com/fweinb)
|
56
|
+
* [Hugo Giraudel](http://twitter.com/hugogiraudel)
|
data/lib/SassyExport.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# SassyExport is a lightweight plugin for SassyJSON
|
2
|
+
# ----------------------------------------------------------------------------------------------------
|
3
|
+
# @online https://github.com/HugoGiraudel/SassyJSON
|
4
|
+
# ----------------------------------------------------------------------------------------------------
|
5
|
+
|
6
|
+
require "SassyJSON"
|
7
|
+
|
8
|
+
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
9
|
+
# Date is in the form of YYYY-MM-DD
|
10
|
+
# ----------------------------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
module SassyExport
|
13
|
+
VERSION = "1.0.0"
|
14
|
+
DATE = "2014-05-31"
|
15
|
+
end
|
16
|
+
|
17
|
+
# SassyJSON : write passed json string to path/to/filename
|
18
|
+
# ----------------------------------------------------------------------------------------------------
|
19
|
+
# @param path [string] : directory path to write string
|
20
|
+
# @param filename [string] : file name to write to path
|
21
|
+
# @param string [string] : json to write to filename
|
22
|
+
# ----------------------------------------------------------------------------------------------------
|
23
|
+
# @return string | write filename to path
|
24
|
+
|
25
|
+
module Sass::Script::Functions
|
26
|
+
def SassyJSON_export(path, filename, string)
|
27
|
+
# define root path up to current folder
|
28
|
+
root = File.dirname(options[:filename] || ".")
|
29
|
+
# open file [create new file if file does not exist], write $string to $root/$path/$filename
|
30
|
+
File.open("#{root}/#{path}/#{filename}.json", "w") { |f| f.write(string) }
|
31
|
+
# return string for use in css
|
32
|
+
return string
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
@import "SassyJSON";
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------------------------------
|
4
|
+
// SassyJSON : write passed json string to $path[/to/filename]
|
5
|
+
// ----------------------------------------------------------------------------------------------------
|
6
|
+
// @param $path [string] : directory path to write to
|
7
|
+
// @param $filename [string] : filename to write at path
|
8
|
+
// @param $map [map] : map to write to filename
|
9
|
+
// ----------------------------------------------------------------------------------------------------
|
10
|
+
// @return creates placeholeder | write filename to path
|
11
|
+
|
12
|
+
@mixin json_export($path, $filename, $map) {
|
13
|
+
@at-root {
|
14
|
+
%json_export {
|
15
|
+
content: "#{SassyJSON_export(unquote($path), unquote($filename), unquote(json_encode($map)))}";
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SassyExport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ezekiel Gabrielse
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: SassyJSON
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
description: SassyExport allows you to export a Sass map into an external JSON file.
|
31
|
+
email:
|
32
|
+
- ezekg@yahoo.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/SassyExport.rb
|
38
|
+
- stylesheets/SassyExport.scss
|
39
|
+
- README.md
|
40
|
+
homepage: https://github.com/ezekg/SassyExport/
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.3.6
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project: SassyExport
|
61
|
+
rubygems_version: 1.8.28
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: SassyExport is a lightweight plugin for SassyJSON that allows you to export
|
65
|
+
an encoded Sass map into an external JSON file.
|
66
|
+
test_files: []
|