alchemia 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c62dfe14b8c81d12118cae0411488b94a66a579
4
+ data.tar.gz: 36453eff0b9c0672639b20f0e19cd86f7941cde5
5
+ SHA512:
6
+ metadata.gz: e32baabb000513b7b30b2a367ef3fe82499138ce7c5b66230be8fb504794107bc32b4bae18c7b9187ae1609070b75349d4ce6158e62c378b0a6f2ac8d2890737
7
+ data.tar.gz: c0e2afa7e3cce00a6820142dd136757f4e2fe722fc95783a61e8bbf6b508c8604cbe7c08d1af4acf264c48b07c6510871d839fa00147adad33556b4deddced3b
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alchemia.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masaaki Morishita
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.
@@ -0,0 +1,51 @@
1
+ # Alchemia
2
+
3
+ Alchemia is Plugin framework for building AltCSS inspired by [Rework](https://github.com/reworkcss/rework).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'alchemia'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install alchemia
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "alchemia"
23
+
24
+ css = ".selector { padding: 10px; }"
25
+
26
+ # Initialize and parse css to AST
27
+ alchemia = Alchemia.new(css)
28
+
29
+ # Include Alchemia plugins
30
+ alchemia.use(awesome_plugin)
31
+
32
+ # Stringify Alchemia AST
33
+ alchemia.to_s
34
+ ```
35
+
36
+ ## API
37
+
38
+ ### Alchemia::use(plugin)
39
+ Include Alchemia plugin.
40
+
41
+ ### Alchemia::to_s
42
+ Stringify processed CSS AST.
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/alchemia/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alchemia/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alchemia"
8
+ spec.version = Alchemia::VERSION
9
+ spec.authors = ["Masaaki Morishita"]
10
+ spec.email = ["ikasama3.0@gmail.com"]
11
+ spec.summary = %q{Plugin framework for building AltCSS}
12
+ spec.description = %q{Plugin framework for building AltCSS in Ruby}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,26 @@
1
+ require "alchemia/version"
2
+ require "alchemia/plugins/base"
3
+ require "crass"
4
+
5
+ class Alchemia
6
+
7
+ def self.parse(css)
8
+ Crass.parse(css, :preserve_comments => true)
9
+ end
10
+
11
+ def initialize(css)
12
+ @tree = Crass.parse(css, :preserve_comments => true)
13
+ end
14
+
15
+ def use(plugin)
16
+ if plugin.class.superclass != Alchemia::Plugins::Base
17
+ raise "Alchemia plugin must extend Alchemia::Plugins::Base"
18
+ end
19
+ plugin.process(@tree)
20
+ end
21
+
22
+ def to_s
23
+ Crass::Parser.stringify(@tree)
24
+ end
25
+
26
+ end
@@ -0,0 +1,64 @@
1
+ class Alchemia
2
+ module Plugins
3
+ class Base
4
+
5
+ def initialize(tree)
6
+ @tree = tree
7
+ end
8
+
9
+ def process
10
+ nil
11
+ end
12
+
13
+ def all_selectors
14
+ selectors = []
15
+ @tree.each do |t|
16
+ if is_rule(t)
17
+ selectors.push t[:selector][:value]
18
+ end
19
+ end
20
+ selectors
21
+ end
22
+
23
+ def selector(selector)
24
+ @tree.each do |t|
25
+ if is_rule(t)
26
+ if selector == t[:selector][:value]
27
+ return t[:selector][:tokens][1][:raw]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def all_properties(selector)
34
+ properties = []
35
+ @tree.each do |t|
36
+ if is_rule(t)
37
+ t[:children].each do |child|
38
+ if is_property(child)
39
+ properties.push child[:name]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ ptoperties
45
+ end
46
+
47
+
48
+ private
49
+
50
+ def is_rule(node)
51
+ true if node[:node] == :style_rule
52
+ end
53
+
54
+ def is_property(node)
55
+ true if node[:property] == :property
56
+ end
57
+
58
+ def is_child(child)
59
+ true if child[:node] == :property
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ class Alchemia
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Alchemia do
4
+ it 'has a version number' do
5
+ expect(Alchemia::VERSION).not_to be nil
6
+ end
7
+
8
+ css = ".selector { padding: 10px; }"
9
+
10
+ it 'Alchemia::parse(css)' do
11
+ expect(Alchemia::parse(css))
12
+ .to eq(
13
+ [{:node=>:style_rule, :selector=>{:node=>:selector, :value=>".selector", :tokens=>[{:node=>:delim, :pos=>0, :raw=>".", :value=>"."}, {:node=>:ident, :pos=>1, :raw=>"selector", :value=>"selector"}, {:node=>:whitespace, :pos=>9, :raw=>" "}]}, :children=>[{:node=>:whitespace, :pos=>11, :raw=>" "}, {:node=>:property, :name=>"padding", :value=>"10px", :children=>[{:node=>:whitespace, :pos=>20, :raw=>" "}, {:node=>:dimension, :pos=>21, :raw=>"10px", :repr=>"10", :type=>:integer, :unit=>"px", :value=>10}], :important=>false, :tokens=>[{:node=>:ident, :pos=>12, :raw=>"padding", :value=>"padding"}, {:node=>:colon, :pos=>19, :raw=>":"}, {:node=>:whitespace, :pos=>20, :raw=>" "}, {:node=>:dimension, :pos=>21, :raw=>"10px", :repr=>"10", :type=>:integer, :unit=>"px", :value=>10}, {:node=>:semicolon, :pos=>25, :raw=>";"}]}, {:node=>:whitespace, :pos=>26, :raw=>" "}]}]
14
+ )
15
+ end
16
+
17
+ alchemia = Alchemia.new(css)
18
+
19
+ it 'Alchemia.use(plugin)' do
20
+ end
21
+
22
+ it 'When plugin do not inherit Alchemia::Plugins::Base, rase error' do
23
+ class TestPlugin
24
+ def process
25
+ end
26
+ end
27
+ plugin = TestPlugin.new
28
+
29
+ proc{alchemia.use(plugin)}.should raise_error
30
+ end
31
+
32
+ it 'Alchemia.to_s' do
33
+ expect(alchemia.to_s).to eq(
34
+ ".selector { padding: 10px; }"
35
+ )
36
+ end
37
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'alchemia'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alchemia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masaaki Morishita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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
+ description: Plugin framework for building AltCSS in Ruby
56
+ email:
57
+ - ikasama3.0@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - alchemia.gemspec
70
+ - lib/alchemia.rb
71
+ - lib/alchemia/plugins/base.rb
72
+ - lib/alchemia/version.rb
73
+ - spec/alchemia_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Plugin framework for building AltCSS
99
+ test_files:
100
+ - spec/alchemia_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: