maca-fork-csspool 2.0.2

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.
Files changed (71) hide show
  1. data/CHANGELOG.rdoc +72 -0
  2. data/History.txt +4 -0
  3. data/Manifest.txt +70 -0
  4. data/README.rdoc +78 -0
  5. data/Rakefile +35 -0
  6. data/lib/csspool.rb +20 -0
  7. data/lib/csspool/collection.rb +50 -0
  8. data/lib/csspool/css.rb +7 -0
  9. data/lib/csspool/css/charset.rb +7 -0
  10. data/lib/csspool/css/declaration.rb +8 -0
  11. data/lib/csspool/css/document.rb +34 -0
  12. data/lib/csspool/css/document_handler.rb +51 -0
  13. data/lib/csspool/css/import_rule.rb +15 -0
  14. data/lib/csspool/css/media.rb +7 -0
  15. data/lib/csspool/css/rule_set.rb +12 -0
  16. data/lib/csspool/lib_croco.rb +78 -0
  17. data/lib/csspool/lib_croco/cr_additional_sel.rb +46 -0
  18. data/lib/csspool/lib_croco/cr_attr_sel.rb +16 -0
  19. data/lib/csspool/lib_croco/cr_doc_handler.rb +24 -0
  20. data/lib/csspool/lib_croco/cr_num.rb +13 -0
  21. data/lib/csspool/lib_croco/cr_parser.rb +11 -0
  22. data/lib/csspool/lib_croco/cr_parsing_location.rb +17 -0
  23. data/lib/csspool/lib_croco/cr_pseudo.rb +14 -0
  24. data/lib/csspool/lib_croco/cr_rgb.rb +18 -0
  25. data/lib/csspool/lib_croco/cr_selector.rb +33 -0
  26. data/lib/csspool/lib_croco/cr_simple_sel.rb +54 -0
  27. data/lib/csspool/lib_croco/cr_term.rb +97 -0
  28. data/lib/csspool/lib_croco/glist.rb +21 -0
  29. data/lib/csspool/node.rb +5 -0
  30. data/lib/csspool/sac.rb +2 -0
  31. data/lib/csspool/sac/document.rb +35 -0
  32. data/lib/csspool/sac/parser.rb +122 -0
  33. data/lib/csspool/selector.rb +35 -0
  34. data/lib/csspool/selectors.rb +8 -0
  35. data/lib/csspool/selectors/additional.rb +6 -0
  36. data/lib/csspool/selectors/attribute.rb +21 -0
  37. data/lib/csspool/selectors/class.rb +11 -0
  38. data/lib/csspool/selectors/id.rb +11 -0
  39. data/lib/csspool/selectors/pseudo_class.rb +13 -0
  40. data/lib/csspool/selectors/simple.rb +22 -0
  41. data/lib/csspool/selectors/type.rb +6 -0
  42. data/lib/csspool/selectors/universal.rb +6 -0
  43. data/lib/csspool/terms.rb +7 -0
  44. data/lib/csspool/terms/function.rb +17 -0
  45. data/lib/csspool/terms/hash.rb +6 -0
  46. data/lib/csspool/terms/ident.rb +15 -0
  47. data/lib/csspool/terms/number.rb +14 -0
  48. data/lib/csspool/terms/rgb.rb +23 -0
  49. data/lib/csspool/terms/string.rb +6 -0
  50. data/lib/csspool/terms/uri.rb +6 -0
  51. data/lib/csspool/visitable.rb +30 -0
  52. data/lib/csspool/visitors.rb +5 -0
  53. data/lib/csspool/visitors/children.rb +50 -0
  54. data/lib/csspool/visitors/comparable.rb +85 -0
  55. data/lib/csspool/visitors/iterator.rb +80 -0
  56. data/lib/csspool/visitors/to_css.rb +188 -0
  57. data/lib/csspool/visitors/visitor.rb +17 -0
  58. data/test/css/test_document.rb +13 -0
  59. data/test/css/test_import_rule.rb +42 -0
  60. data/test/helper.rb +67 -0
  61. data/test/sac/test_parser.rb +115 -0
  62. data/test/sac/test_properties.rb +43 -0
  63. data/test/sac/test_terms.rb +134 -0
  64. data/test/test_collection.rb +81 -0
  65. data/test/test_parser.rb +91 -0
  66. data/test/test_selector.rb +47 -0
  67. data/test/visitors/test_children.rb +20 -0
  68. data/test/visitors/test_comparable.rb +103 -0
  69. data/test/visitors/test_each.rb +19 -0
  70. data/test/visitors/test_to_css.rb +200 -0
  71. metadata +173 -0
@@ -0,0 +1,72 @@
1
+ == 2.0.2
2
+
3
+ * Selector '#a > #b', '#a #b' and the like where not converted correctly to css. fixed [Maca]
4
+
5
+ == 2.0.0
6
+
7
+ * Bugfixes
8
+
9
+ * Uh... Many.
10
+
11
+ * New Features
12
+
13
+ * Now wraps libcroco via FFI
14
+
15
+ == 0.2.6
16
+
17
+ * Fix comment greediness. [Seth Rasmussen]
18
+
19
+ == 0.2.5
20
+
21
+ * Accepting spaces after error rules.
22
+ * Comments with asterisks tokenize correctly. [Seth Rasmussen]
23
+ * Stop polluting the global namespace with includes. [Thomas Kadauke]
24
+
25
+ == 0.2.4
26
+
27
+ * Fixed error handling on at rules. Thanks Dan for tests!
28
+ * Made specificity an array
29
+ * Made StyleSheet::Rule comparable on specificity
30
+
31
+ == 0.2.3
32
+
33
+ * Fixed a bug where nil selectors on conditional selectors were being visited.
34
+
35
+ == 0.2.2
36
+
37
+ * I suck.
38
+
39
+ == 0.2.1
40
+
41
+ * Recovering from unexpected tokens in the properties section.
42
+
43
+ == 0.2.0
44
+
45
+ * Added CSS::SAC::Parser#parse_rule to parse a single rule.
46
+ * Added CSS::StyleSheet#find_rule for finding a particular rule.
47
+ * Added CSS::StyleSheet#rules_matching for finding all rules matching a node.
48
+ * Added CSS::StyleSheet#create_rule for creating a new rule.
49
+ * Added CSS::StyleSheet#find_all_rules_matching for finding all rules that match
50
+ any node in the passed in document.
51
+ * Added .eql? to selector AST
52
+ * Added .hash to selector AST
53
+ * Added .eql? to LexicalUnits
54
+ * Added .hash to LexicalUnits
55
+ * Added CSS::StyleSheet#to_css
56
+ * Added CSS::StyleSheet#reduce!
57
+ * CSS::StyleSheet is now the default document handler
58
+
59
+ == 0.1.1
60
+
61
+ * Added specificity to selectors.
62
+ * Added == to selector ASTs.
63
+ * Added =~ to selector ASTs. The object passed in to =~ must quack like an
64
+ hpricot node. It must implement the following methods: name, parent, child,
65
+ next_sibling, attributes.
66
+ * Added .to_xpath to the selector AST.
67
+ * Fixed a bug where functions as pseudo classes didn't parse.
68
+
69
+ == 0.1.0
70
+
71
+ * Birthday!
72
+
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-10-23
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,70 @@
1
+ CHANGELOG.rdoc
2
+ History.txt
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/csspool.rb
7
+ lib/csspool/collection.rb
8
+ lib/csspool/css.rb
9
+ lib/csspool/css/charset.rb
10
+ lib/csspool/css/declaration.rb
11
+ lib/csspool/css/document.rb
12
+ lib/csspool/css/document_handler.rb
13
+ lib/csspool/css/import_rule.rb
14
+ lib/csspool/css/media.rb
15
+ lib/csspool/css/rule_set.rb
16
+ lib/csspool/lib_croco.rb
17
+ lib/csspool/lib_croco/cr_additional_sel.rb
18
+ lib/csspool/lib_croco/cr_attr_sel.rb
19
+ lib/csspool/lib_croco/cr_doc_handler.rb
20
+ lib/csspool/lib_croco/cr_num.rb
21
+ lib/csspool/lib_croco/cr_parser.rb
22
+ lib/csspool/lib_croco/cr_parsing_location.rb
23
+ lib/csspool/lib_croco/cr_pseudo.rb
24
+ lib/csspool/lib_croco/cr_rgb.rb
25
+ lib/csspool/lib_croco/cr_selector.rb
26
+ lib/csspool/lib_croco/cr_simple_sel.rb
27
+ lib/csspool/lib_croco/cr_term.rb
28
+ lib/csspool/lib_croco/glist.rb
29
+ lib/csspool/node.rb
30
+ lib/csspool/sac.rb
31
+ lib/csspool/sac/document.rb
32
+ lib/csspool/sac/parser.rb
33
+ lib/csspool/selector.rb
34
+ lib/csspool/selectors.rb
35
+ lib/csspool/selectors/additional.rb
36
+ lib/csspool/selectors/attribute.rb
37
+ lib/csspool/selectors/class.rb
38
+ lib/csspool/selectors/id.rb
39
+ lib/csspool/selectors/pseudo_class.rb
40
+ lib/csspool/selectors/simple.rb
41
+ lib/csspool/selectors/type.rb
42
+ lib/csspool/selectors/universal.rb
43
+ lib/csspool/terms.rb
44
+ lib/csspool/terms/function.rb
45
+ lib/csspool/terms/hash.rb
46
+ lib/csspool/terms/ident.rb
47
+ lib/csspool/terms/number.rb
48
+ lib/csspool/terms/rgb.rb
49
+ lib/csspool/terms/string.rb
50
+ lib/csspool/terms/uri.rb
51
+ lib/csspool/visitable.rb
52
+ lib/csspool/visitors.rb
53
+ lib/csspool/visitors/children.rb
54
+ lib/csspool/visitors/comparable.rb
55
+ lib/csspool/visitors/iterator.rb
56
+ lib/csspool/visitors/to_css.rb
57
+ lib/csspool/visitors/visitor.rb
58
+ test/css/test_document.rb
59
+ test/css/test_import_rule.rb
60
+ test/helper.rb
61
+ test/sac/test_parser.rb
62
+ test/sac/test_properties.rb
63
+ test/sac/test_terms.rb
64
+ test/test_collection.rb
65
+ test/test_parser.rb
66
+ test/test_selector.rb
67
+ test/visitors/test_children.rb
68
+ test/visitors/test_comparable.rb
69
+ test/visitors/test_each.rb
70
+ test/visitors/test_to_css.rb
@@ -0,0 +1,78 @@
1
+ = CSSPool
2
+
3
+ * http://csspool.rubyforge.org
4
+ * http://github.com/tenderlove/csspool
5
+
6
+ == DESCRIPTION:
7
+
8
+ CSSPool is a CSS parser. CSSPool provides a SAC interface for parsing CSS as
9
+ well as a document oriented interface for parsing CSS.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ CSSPool now depends on libcroco[http://www.freespiders.org/projects/libcroco/]
14
+ and interfaces with libcroco via FFI. This means that if libcroco isn't
15
+ installed in one of your default library paths, you'll need to tell CSSPool
16
+ where to find the libcroco shared library. This is typically the case for
17
+ people using OS X and installing libcroco via macports.
18
+
19
+ You can tell CSSPool where to find the libcroco shared library in a couple ways.
20
+ The first way is to set LD_LIBRARY_PATH to point at the correct directory. Just
21
+ do this:
22
+
23
+ $ export LD_LIBRARY_PATH=/opt/local/lib
24
+
25
+ Then run your script.
26
+
27
+ The second way is to tell CSSPool specifically where to find the dynamic
28
+ library. To do that, just set the LIBCROCO environment variable. On OS X,
29
+ I would do this:
30
+
31
+ $ export LIBCROCO=/opt/local/lib/libcroco-0.6.dylib
32
+
33
+ Then run my script.
34
+
35
+ == SYNOPSIS:
36
+
37
+ doc = CSSPool.CSS open('/path/to/css.css')
38
+ doc.rule_sets.each do |rs|
39
+ puts rs.to_css
40
+ end
41
+
42
+ puts doc.to_css
43
+
44
+ == REQUIREMENTS:
45
+
46
+ * libcroco (on OS X do "sudo port install libcroco")
47
+
48
+ == INSTALL:
49
+
50
+ * sudo gem install csspool
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2007-2009
57
+
58
+ * {Aaron Patterson}[http://tenderlovemaking.com]
59
+ * {John Barnette}[http://www.jbarnette.com/]
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of this software and associated documentation files (the
63
+ 'Software'), to deal in the Software without restriction, including
64
+ without limitation the rights to use, copy, modify, merge, publish,
65
+ distribute, sublicense, and/or sell copies of the Software, and to
66
+ permit persons to whom the Software is furnished to do so, subject to
67
+ the following conditions:
68
+
69
+ The above copyright notice and this permission notice shall be
70
+ included in all copies or substantial portions of the Software.
71
+
72
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
73
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
75
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
76
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
77
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
78
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ %w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
3
+ require File.dirname(__FILE__) + '/lib/csspool'
4
+
5
+ $hoe = Hoe.new('maca-fork-csspool', CSSPool::VERSION) do |p|
6
+ p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
7
+ p.developer('John Barnette', 'jabarnette@rubyforge.org')
8
+
9
+ p.changes = p.paragraphs_of("CHANGELOG.rdoc", 0..1).join("\n"*2)
10
+ p.extra_dev_deps = [
11
+ ['newgem', ">= #{::Newgem::VERSION}"]
12
+ ]
13
+ p.extra_deps = ['ffi']
14
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
15
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
16
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
17
+ p.rsync_args = '-av --delete --ignore-errors'
18
+ end
19
+
20
+ require 'newgem/tasks' # load /tasks/*.rake
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+
24
+ # require 'rubygems'
25
+ # require 'hoe'
26
+
27
+
28
+ # Hoe.spec('csspool') do
29
+ # developer('Aaron Patterson', 'aaronp@rubyforge.org')
30
+ # developer('John Barnette', 'jabarnette@rubyforge.org')
31
+ # self.readme_file = 'README.rdoc'
32
+ # self.history_file = 'CHANGELOG.rdoc'
33
+ # self.extra_rdoc_files = FileList['*.rdoc']
34
+ # self.extra_deps = ['ffi']
35
+ # end
@@ -0,0 +1,20 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'csspool/visitable'
4
+ require 'csspool/node'
5
+ require 'csspool/selectors'
6
+ require 'csspool/terms'
7
+ require 'csspool/selector'
8
+ require 'csspool/sac'
9
+ require 'csspool/lib_croco'
10
+ require 'csspool/css'
11
+ require 'csspool/visitors'
12
+ require 'csspool/collection'
13
+
14
+ module CSSPool
15
+ VERSION = "2.0.2"
16
+
17
+ def self.CSS doc
18
+ CSSPool::CSS::Document.parse doc
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ module CSSPool
2
+ class Collection
3
+ include Enumerable
4
+
5
+ def initialize &block
6
+ @docs = []
7
+ @block = block
8
+ end
9
+
10
+ def << string
11
+ doc = CSSPool.CSS string
12
+
13
+ import_tree = [[doc]]
14
+
15
+ imported_urls = {}
16
+
17
+ until import_tree.last.all? { |x| x.import_rules.length == 0 }
18
+ level = import_tree.last
19
+ import_tree << []
20
+ level.each do |doc|
21
+ doc.import_rules.each do |ir|
22
+ next if imported_urls.key? ir.uri
23
+
24
+ new_doc = ir.load(&@block)
25
+
26
+ imported_urls[ir.uri] = ir.load(&@block)
27
+ import_tree.last << new_doc
28
+ end
29
+ end
30
+ end
31
+
32
+ @docs += import_tree.flatten.reverse
33
+ self
34
+ end
35
+
36
+ def length
37
+ @docs.length
38
+ end
39
+
40
+ def [] idx
41
+ @docs[idx]
42
+ end
43
+
44
+ def each &block
45
+ @docs.each(&block)
46
+ end
47
+
48
+ def last; @docs.last; end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ require 'csspool/css/charset'
2
+ require 'csspool/css/import_rule'
3
+ require 'csspool/css/media'
4
+ require 'csspool/css/rule_set'
5
+ require 'csspool/css/declaration'
6
+ require 'csspool/css/document'
7
+ require 'csspool/css/document_handler'
@@ -0,0 +1,7 @@
1
+ module CSSPool
2
+ module CSS
3
+ class Charset < Struct.new(:name, :parse_location)
4
+ include CSSPool::Visitable
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module CSSPool
2
+ module CSS
3
+ class Declaration < Struct.new(:property, :expressions, :important, :rule_set)
4
+ include CSSPool::Visitable
5
+ alias :important? :important
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ module CSSPool
2
+ module CSS
3
+ class Document < Node
4
+ def self.parse string
5
+ unless string && string.length > 0
6
+ return CSSPool::CSS::Document.new
7
+ end
8
+ handler = CSSPool::CSS::DocumentHandler.new
9
+ parser = CSSPool::SAC::Parser.new(handler)
10
+ parser.parse(string)
11
+ handler.document
12
+ end
13
+
14
+ attr_accessor :rule_sets
15
+ attr_accessor :charsets
16
+ attr_accessor :import_rules
17
+ attr_accessor :parent
18
+ attr_accessor :parent_import_rule
19
+
20
+ def initialize
21
+ @rule_sets = []
22
+ @charsets = []
23
+ @import_rules = []
24
+ @parent = nil
25
+ @parent_import_rule = nil
26
+ end
27
+
28
+ def [] selector
29
+ selectors = CSSPool.CSS("#{selector} {}").rule_sets.first.selectors
30
+ rule_sets.find_all { |rs| rs.selectors == selectors}
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,51 @@
1
+ module CSSPool
2
+ module CSS
3
+ class DocumentHandler < CSSPool::SAC::Document
4
+ attr_accessor :document
5
+
6
+ def initialize
7
+ @document = nil
8
+ @media_stack = []
9
+ end
10
+
11
+ def start_document
12
+ @document = CSSPool::CSS::Document.new
13
+ end
14
+
15
+ def charset name, location
16
+ @document.charsets << CSS::Charset.new(name, location)
17
+ end
18
+
19
+ def import_style media_list, uri, ns, loc
20
+ @document.import_rules << CSS::ImportRule.new(
21
+ uri,
22
+ ns,
23
+ media_list.map { |x| CSS::Media.new(x, loc) },
24
+ @document,
25
+ loc
26
+ )
27
+ end
28
+
29
+ def start_selector selector_list
30
+ @document.rule_sets << RuleSet.new(
31
+ selector_list,
32
+ [],
33
+ @media_stack.last || []
34
+ )
35
+ end
36
+
37
+ def property name, exp, important
38
+ rs = @document.rule_sets.last
39
+ rs.declarations << Declaration.new(name, exp, important, rs)
40
+ end
41
+
42
+ def start_media media_list, parse_location
43
+ @media_stack << media_list.map { |x| CSS::Media.new(x, parse_location) }
44
+ end
45
+
46
+ def end_media media_list, parse_location
47
+ @media_stack.pop
48
+ end
49
+ end
50
+ end
51
+ end