csspool 2.0.0 → 3.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.
Files changed (57) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Manifest.txt +10 -14
  4. data/README.rdoc +8 -21
  5. data/Rakefile +36 -2
  6. data/lib/csspool/collection.rb +2 -2
  7. data/lib/csspool/css/charset.rb +8 -2
  8. data/lib/csspool/css/declaration.rb +13 -2
  9. data/lib/csspool/css/document_handler.rb +3 -3
  10. data/lib/csspool/css/import_rule.rb +15 -3
  11. data/lib/csspool/css/media.rb +8 -2
  12. data/lib/csspool/css/parser.rb +1090 -0
  13. data/lib/csspool/css/parser.y +347 -0
  14. data/lib/csspool/css/rule_set.rb +8 -3
  15. data/lib/csspool/css/tokenizer.rb +228 -0
  16. data/lib/csspool/css/tokenizer.rex +96 -0
  17. data/lib/csspool/css.rb +1 -0
  18. data/lib/csspool/node.rb +29 -1
  19. data/lib/csspool/sac/document.rb +3 -3
  20. data/lib/csspool/sac/parser.rb +6 -112
  21. data/lib/csspool/terms/function.rb +1 -1
  22. data/lib/csspool/terms/ident.rb +1 -1
  23. data/lib/csspool/terms/number.rb +1 -1
  24. data/lib/csspool/terms/rgb.rb +1 -4
  25. data/lib/csspool/terms/string.rb +1 -1
  26. data/lib/csspool/visitors/children.rb +50 -0
  27. data/lib/csspool/visitors/comparable.rb +9 -3
  28. data/lib/csspool/visitors/iterator.rb +80 -0
  29. data/lib/csspool/visitors/to_css.rb +61 -45
  30. data/lib/csspool/visitors.rb +2 -0
  31. data/lib/csspool.rb +6 -3
  32. data/test/css/test_parser.rb +412 -0
  33. data/test/css/test_tokenizer.rb +320 -0
  34. data/test/helper.rb +2 -2
  35. data/test/sac/test_parser.rb +3 -8
  36. data/test/sac/test_terms.rb +128 -34
  37. data/test/test_collection.rb +1 -1
  38. data/test/test_parser.rb +1 -1
  39. data/test/visitors/test_children.rb +20 -0
  40. data/test/visitors/test_comparable.rb +31 -1
  41. data/test/visitors/test_each.rb +19 -0
  42. data/test/visitors/test_to_css.rb +125 -1
  43. metadata +90 -68
  44. data/lib/csspool/lib_croco/cr_additional_sel.rb +0 -46
  45. data/lib/csspool/lib_croco/cr_attr_sel.rb +0 -16
  46. data/lib/csspool/lib_croco/cr_doc_handler.rb +0 -24
  47. data/lib/csspool/lib_croco/cr_num.rb +0 -13
  48. data/lib/csspool/lib_croco/cr_parser.rb +0 -11
  49. data/lib/csspool/lib_croco/cr_parsing_location.rb +0 -17
  50. data/lib/csspool/lib_croco/cr_pseudo.rb +0 -14
  51. data/lib/csspool/lib_croco/cr_rgb.rb +0 -18
  52. data/lib/csspool/lib_croco/cr_selector.rb +0 -34
  53. data/lib/csspool/lib_croco/cr_simple_sel.rb +0 -54
  54. data/lib/csspool/lib_croco/cr_term.rb +0 -97
  55. data/lib/csspool/lib_croco/glist.rb +0 -21
  56. data/lib/csspool/lib_croco.rb +0 -78
  57. data/lib/csspool/visitable.rb +0 -18
data/.gemtest ADDED
File without changes
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 3.0.0
2
+
3
+ * New Features
4
+
5
+ * Pure ruby: no longer uses C based back end.
6
+
1
7
  == 2.0.0
2
8
 
3
9
  * Bugfixes
data/Manifest.txt CHANGED
@@ -12,20 +12,11 @@ lib/csspool/css/document.rb
12
12
  lib/csspool/css/document_handler.rb
13
13
  lib/csspool/css/import_rule.rb
14
14
  lib/csspool/css/media.rb
15
+ lib/csspool/css/parser.rb
16
+ lib/csspool/css/parser.y
15
17
  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
18
+ lib/csspool/css/tokenizer.rb
19
+ lib/csspool/css/tokenizer.rex
29
20
  lib/csspool/node.rb
30
21
  lib/csspool/sac.rb
31
22
  lib/csspool/sac/document.rb
@@ -48,13 +39,16 @@ lib/csspool/terms/number.rb
48
39
  lib/csspool/terms/rgb.rb
49
40
  lib/csspool/terms/string.rb
50
41
  lib/csspool/terms/uri.rb
51
- lib/csspool/visitable.rb
52
42
  lib/csspool/visitors.rb
43
+ lib/csspool/visitors/children.rb
53
44
  lib/csspool/visitors/comparable.rb
45
+ lib/csspool/visitors/iterator.rb
54
46
  lib/csspool/visitors/to_css.rb
55
47
  lib/csspool/visitors/visitor.rb
56
48
  test/css/test_document.rb
57
49
  test/css/test_import_rule.rb
50
+ test/css/test_parser.rb
51
+ test/css/test_tokenizer.rb
58
52
  test/helper.rb
59
53
  test/sac/test_parser.rb
60
54
  test/sac/test_properties.rb
@@ -62,5 +56,7 @@ test/sac/test_terms.rb
62
56
  test/test_collection.rb
63
57
  test/test_parser.rb
64
58
  test/test_selector.rb
59
+ test/visitors/test_children.rb
65
60
  test/visitors/test_comparable.rb
61
+ test/visitors/test_each.rb
66
62
  test/visitors/test_to_css.rb
data/README.rdoc CHANGED
@@ -10,27 +10,13 @@ well as a document oriented interface for parsing CSS.
10
10
 
11
11
  == FEATURES/PROBLEMS:
12
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.
13
+ CSSPool no longer depends on libcroco! There is now a dependency on both the
14
+ {racc}[http://github.com/tenderlove/racc] and
15
+ {rexical}[http://github.com/tenderlove/rexical] gems, so make sure to install
16
+ them first.
18
17
 
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.
18
+ $ sudo gem install racc
19
+ $ sudo gem install rexical
34
20
 
35
21
  == SYNOPSIS:
36
22
 
@@ -43,7 +29,8 @@ Then run my script.
43
29
 
44
30
  == REQUIREMENTS:
45
31
 
46
- * libcroco (on OS X do "sudo port install libcroco")
32
+ * racc ("sudo gem install racc")
33
+ * rexical ("sudo gem install rexical")
47
34
 
48
35
  == INSTALL:
49
36
 
data/Rakefile CHANGED
@@ -3,12 +3,46 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
+ GENERATED_TOKENIZER = "lib/csspool/css/tokenizer.rb"
7
+ GENERATED_PARSER = "lib/csspool/css/parser.rb"
8
+
9
+ Hoe.plugin :git
10
+
6
11
  Hoe.spec('csspool') do
7
12
  developer('Aaron Patterson', 'aaronp@rubyforge.org')
8
- developer('John Barnette', 'jabarnette@rubyforge.org')
13
+ developer('John Barnette', 'jbarnette@rubyforge.org')
9
14
  self.readme_file = 'README.rdoc'
10
15
  self.history_file = 'CHANGELOG.rdoc'
11
- self.extra_deps = ['ffi']
16
+ self.extra_rdoc_files = FileList['*.rdoc']
17
+
18
+ %w{ racc rexical }.each do |dep|
19
+ self.extra_dev_deps << [dep, '>= 0']
20
+ end
21
+ end
22
+
23
+ [:test, :check_manifest].each do |task_name|
24
+ Rake::Task[task_name].prerequisites << :compile
25
+ end
26
+
27
+ task :compile => [GENERATED_TOKENIZER, GENERATED_PARSER]
28
+
29
+ file GENERATED_TOKENIZER => "lib/csspool/css/tokenizer.rex" do |t|
30
+ begin
31
+ sh "rex -i --independent -o #{t.name} #{t.prerequisites.first}"
32
+ rescue
33
+ abort "need rexical, sudo gem install rexical"
34
+ end
35
+ end
36
+
37
+ file GENERATED_PARSER => "lib/csspool/css/parser.y" do |t|
38
+ begin
39
+ racc = `which racc`.strip
40
+ racc = "#{::Config::CONFIG['bindir']}/racc" if racc.empty?
41
+ #sh "#{racc} -l -o #{t.name} #{t.prerequisites.first}"
42
+ sh "#{racc} -o #{t.name} #{t.prerequisites.first}"
43
+ rescue
44
+ abort "need racc, sudo gem install racc"
45
+ end
12
46
  end
13
47
 
14
48
  # vim: syntax=Ruby
@@ -17,8 +17,8 @@ module CSSPool
17
17
  until import_tree.last.all? { |x| x.import_rules.length == 0 }
18
18
  level = import_tree.last
19
19
  import_tree << []
20
- level.each do |doc|
21
- doc.import_rules.each do |ir|
20
+ level.each do |l|
21
+ l.import_rules.each do |ir|
22
22
  next if imported_urls.key? ir.uri
23
23
 
24
24
  new_doc = ir.load(&@block)
@@ -1,7 +1,13 @@
1
1
  module CSSPool
2
2
  module CSS
3
- class Charset < Struct.new(:name, :parse_location)
4
- include CSSPool::Visitable
3
+ class Charset < CSSPool::Node
4
+ attr_accessor :name
5
+ attr_accessor :parse_location
6
+
7
+ def initialize name, parse_location
8
+ @name = name
9
+ @parse_location = parse_location
10
+ end
5
11
  end
6
12
  end
7
13
  end
@@ -1,8 +1,19 @@
1
1
  module CSSPool
2
2
  module CSS
3
- class Declaration < Struct.new(:property, :expressions, :important, :rule_set)
4
- include CSSPool::Visitable
3
+ class Declaration < CSSPool::Node
4
+ attr_accessor :property
5
+ attr_accessor :expressions
6
+ attr_accessor :important
7
+ attr_accessor :rule_set
8
+
5
9
  alias :important? :important
10
+
11
+ def initialize property, expressions, important, rule_set
12
+ @property = property
13
+ @expressions = expressions
14
+ @important = important
15
+ @rule_set = rule_set
16
+ end
6
17
  end
7
18
  end
8
19
  end
@@ -16,7 +16,7 @@ module CSSPool
16
16
  @document.charsets << CSS::Charset.new(name, location)
17
17
  end
18
18
 
19
- def import_style media_list, uri, ns, loc
19
+ def import_style media_list, uri, ns = nil, loc = {}
20
20
  @document.import_rules << CSS::ImportRule.new(
21
21
  uri,
22
22
  ns,
@@ -39,11 +39,11 @@ module CSSPool
39
39
  rs.declarations << Declaration.new(name, exp, important, rs)
40
40
  end
41
41
 
42
- def start_media media_list, parse_location
42
+ def start_media media_list, parse_location = {}
43
43
  @media_stack << media_list.map { |x| CSS::Media.new(x, parse_location) }
44
44
  end
45
45
 
46
- def end_media media_list, parse_location
46
+ def end_media media_list, parse_location = {}
47
47
  @media_stack.pop
48
48
  end
49
49
  end
@@ -1,10 +1,22 @@
1
1
  module CSSPool
2
2
  module CSS
3
- class ImportRule < Struct.new(:uri, :namespace, :media, :document, :parse_location)
4
- include CSSPool::Visitable
3
+ class ImportRule < CSSPool::Node
4
+ attr_accessor :uri
5
+ attr_accessor :namespace
6
+ attr_accessor :media
7
+ attr_accessor :document
8
+ attr_accessor :parse_location
9
+
10
+ def initialize uri, namespace, media, document, parse_location
11
+ @uri = uri
12
+ @namespace = namespace
13
+ @media = media
14
+ @document = document
15
+ @parse_location = parse_location
16
+ end
5
17
 
6
18
  def load
7
- new_doc = CSSPool.CSS(yield uri)
19
+ new_doc = CSSPool.CSS(yield uri.value)
8
20
  new_doc.parent_import_rule = self
9
21
  new_doc.parent = document
10
22
  new_doc.rule_sets.each { |rs| rs.media = media }
@@ -1,7 +1,13 @@
1
1
  module CSSPool
2
2
  module CSS
3
- class Media < Struct.new(:name, :parse_location)
4
- include CSSPool::Visitable
3
+ class Media < CSSPool::Node
4
+ attr_accessor :name
5
+ attr_accessor :parse_location
6
+
7
+ def initialize name, parse_location
8
+ @name = name
9
+ @parse_location = parse_location
10
+ end
5
11
  end
6
12
  end
7
13
  end