themify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8489589d02b715f6dca40abdb32fb822e27d1b4c
4
+ data.tar.gz: 3a8214fcc37a198cdd8d885787b71f1f35d3a338
5
+ SHA512:
6
+ metadata.gz: b56e6d1bf18b5806dbf054fcc7cb7d3001d4422eab19a601acab823feba810d7bca6825e7ae4a2f1e2a86992bfb26948482585992831cf93ea7b616f52fdc0d0
7
+ data.tar.gz: a176ddd39db60eeb32c8fd0e59ec23e7e266ee68f5f1078ec3d87f9b347e64d7d91d34063c19b8cf40b0dd25442310a25f73f0dc778d94df8c053dbb874a31b3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in themify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alessandro Tagliapietra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Themify
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'themify'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install themify
20
+
21
+ ## Usage
22
+
23
+ ### CSS
24
+
25
+ Use an initializer to add one or more templates:
26
+
27
+ ```ruby
28
+ Themify.add_template(Themify::Template.new('light', {'main' => '#00ccff', 'secondary' => '#121234'}))
29
+ Themify.add_template(Themify::Template.new('dark', {'main' => '#aa33ff', 'secondary' => '#565667'}))
30
+ ```
31
+
32
+ Create a new file with extension `.css.sass.template` and use variables with prefix `$template_`.
33
+ For example this template:
34
+
35
+ ```ruby
36
+ .label
37
+ background: $template_main
38
+ ```
39
+
40
+ generates
41
+
42
+ ```css
43
+ /* Template 1 */
44
+ .template-light .label {
45
+ background: #00ccff;
46
+ }
47
+
48
+ /* Template 2 */
49
+ .template-dark .label {
50
+ background: #aa33ff;
51
+ }
52
+ ```
53
+
54
+ now you've just to create a parent element with the corresponding theme class.
55
+
56
+ ### Javascript
57
+
58
+ You can also access templates via javascript by requiring the library in your assets pipeline:
59
+
60
+ ```coffeescript
61
+ #= require themify
62
+ ```
63
+
64
+ then you can use `window.Themify.templates` to have the array of templates like this:
65
+
66
+ ```json
67
+ [
68
+ {
69
+ "name": "light",
70
+ "colors": {
71
+ "main": "#00ccff",
72
+ "secondary": "#121234"
73
+ }
74
+ },
75
+ {
76
+ "name": "dark",
77
+ "colors": {
78
+ "main": "#aa33ff",
79
+ "secondary": "#565667"
80
+ }
81
+ }
82
+ ]
83
+ ```
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it ( https://github.com/alex88/themify/fork )
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,2 @@
1
+ <%# encoding: UTF-8 %>
2
+ <%= Themify.generate_js %>
@@ -0,0 +1,12 @@
1
+ require 'active_support/ordered_options'
2
+
3
+ module Themify
4
+ class Railtie < Rails::Engine
5
+ config.themify = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer 'sprockets.themify', after: 'sprockets.environment', group: :all do |app|
8
+ next unless app.assets
9
+ app.assets.register_engine('.template', Themify::TemplateEngine)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Themify
2
+ class Template
3
+ attr_reader :colors
4
+ attr_reader :name
5
+
6
+ @colors = {}
7
+ @name = nil
8
+
9
+ # Creates a new template
10
+ # Takes an hash as argument
11
+ # { 'primary': '#ccffee' }
12
+ def initialize(name, colors)
13
+ raise 'You should pass an hash of key values for colors and a string as name' unless colors.instance_of?(Hash) && name.instance_of?(String)
14
+ @name = name
15
+ @colors = colors
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ require 'sprockets'
2
+ require 'tilt'
3
+ require 'sass'
4
+
5
+ module Themify
6
+ class TemplateEngine < Tilt::Template
7
+ def self.default_mime_type; 'text/css'; end
8
+
9
+ def prepare
10
+ @templates = Themify.templates
11
+ end
12
+
13
+ def evaluate(scope, locals, &block)
14
+ css_files = []
15
+ @templates.each.with_index do |template, template_index|
16
+ tree = ::Sass::Engine.new(data, sass_options).to_tree
17
+ process_node tree, template, template_index + 1
18
+ css_files << tree.to_sass
19
+ end
20
+ out = ''
21
+ css_files.each.with_index { |css, i| out << "/* Template #{i+1} */\n\n#{css} \n" }
22
+ out
23
+ end
24
+
25
+ private
26
+ def sass_options
27
+ options.merge filename: eval_file, line: line, syntax: :sass
28
+ end
29
+
30
+ def process_node node, template, template_index
31
+ if node.is_a?(Sass::Tree::RootNode)
32
+ template_root = Sass::Tree::RuleNode.new([".template-#{template.name}"])
33
+ template_root.children = node.children
34
+ node.children = [template_root]
35
+ end
36
+ if node.has_children
37
+ node.children.each { |node| process_node node, template, template_index }
38
+ elsif node.is_a?(Sass::Tree::PropNode)
39
+ if node.value.is_a?(Sass::Script::Tree::ListLiteral)
40
+ node.value.children.each.with_index do |element, i|
41
+ if element.is_a?(Sass::Script::Tree::Variable) && element.name =~ /template_[\w]+/
42
+ node.value.children[i] = Sass::Script::Parser.parse(template.colors[element.name[/template_([\w]+)/,1]], 0, 0)
43
+ end
44
+ end
45
+ end
46
+ if node.value.is_a?(Sass::Script::Tree::Variable) && node.value.name =~ /template_[\w]+/
47
+ node.value = Sass::Script::Parser.parse(template.colors[node.value.name[/template_([\w]+)/,1]], 0, 0)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Themify
2
+ VERSION = '0.0.1'
3
+ end
data/lib/themify.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'themify/version'
2
+ require 'themify/template'
3
+ require 'themify/template_engine'
4
+ require 'themify/engine'
5
+
6
+ module Themify
7
+ class << self
8
+ attr_accessor :templates
9
+ end
10
+ @templates = []
11
+
12
+ # Adds a template to an internal list of templates
13
+ # Argument must be an instance of Themify::Template
14
+ def self.add_template(template)
15
+ self.templates ||= []
16
+ self.templates << template
17
+ end
18
+
19
+ def self.generate_js
20
+ 'window.Themify = {}; window.Themify.templates = ' + templates.to_json
21
+ end
22
+ end
data/themify.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'themify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'themify'
8
+ spec.version = Themify::VERSION
9
+ spec.authors = ['Alessandro Tagliapietra']
10
+ spec.email = ['tagliapietra.alessandro@gmail.com']
11
+ spec.summary = %q{Manage themes that can be used in SASS and JS files}
12
+ spec.description = %q{With themify you can handle multiple themes and generate css and js files}
13
+ spec.homepage = 'https://github.com/alex88/themify'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'sass'
22
+ spec.add_dependency 'rails', '>= 3.1.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: themify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Tagliapietra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
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: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.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: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: With themify you can handle multiple themes and generate css and js files
70
+ email:
71
+ - tagliapietra.alessandro@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - app/assets/javascripts/themify.js.erb
82
+ - lib/themify.rb
83
+ - lib/themify/engine.rb
84
+ - lib/themify/template.rb
85
+ - lib/themify/template_engine.rb
86
+ - lib/themify/version.rb
87
+ - themify.gemspec
88
+ homepage: https://github.com/alex88/themify
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Manage themes that can be used in SASS and JS files
112
+ test_files: []