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
@@ -1,97 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRTerm < FFI::Struct
4
- layout(
5
- :type, :int,
6
- :unary_op, :int,
7
- :operator, :int,
8
- :content, :pointer,
9
- :ext_content, :pointer,
10
- :app_data, :pointer,
11
- :ref_count, :long,
12
- :next, :pointer,
13
- :pref, :pointer,
14
- :line, :int,
15
- :column, :int,
16
- :byte_offset, :int
17
- )
18
-
19
- def to_term
20
- operator = {
21
- 0 => nil,
22
- 1 => '/',
23
- 2 => ','
24
- }[self[:operator]]
25
-
26
- unary_op = {
27
- 0 => nil,
28
- 1 => :plus,
29
- 2 => :minus
30
- }[self[:unary_op]]
31
-
32
- case self[:type]
33
- when 0 # TERM_NO_TYPE
34
- when 1 # TERM_NUMBER
35
- num = CRNum.new(self[:content])
36
- CSSPool::Terms::Number.new(
37
- num[:type],
38
- unary_op,
39
- num[:value],
40
- operator,
41
- LibCroco.location_to_h(self)
42
- )
43
- when 2 # TERM_FUNCTION
44
- name = LibCroco.cr_string_peek_raw_str(self[:content]).read_string
45
- params = []
46
- term = self[:ext_content]
47
- until term.null?
48
- params << LibCroco::CRTerm.new(term)
49
- term = params.last[:next]
50
- end
51
- CSSPool::Terms::Function.new(
52
- name,
53
- params.map { |param| param.to_term },
54
- operator,
55
- LibCroco.location_to_h(self)
56
- )
57
- when 3 # TERM_STRING
58
- CSSPool::Terms::String.new(
59
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
60
- operator,
61
- LibCroco.location_to_h(self)
62
- )
63
- when 4 # TERM_IDENT
64
- CSSPool::Terms::Ident.new(
65
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
66
- operator,
67
- LibCroco.location_to_h(self)
68
- )
69
- when 5 # TERM_URI
70
- CSSPool::Terms::URI.new(
71
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
72
- operator,
73
- LibCroco.location_to_h(self)
74
- )
75
- when 6 # TERM_RGB
76
- rgb = LibCroco::CRRgb.new(self[:content])
77
- CSSPool::Terms::Rgb.new(
78
- rgb[:red],
79
- rgb[:green],
80
- rgb[:blue],
81
- rgb[:is_percentage] == 1,
82
- operator,
83
- LibCroco.location_to_h(rgb)
84
- )
85
- when 7 # TERM_UNICODERANGE
86
- raise "libcroco doesn't seem to support this term"
87
- when 8 # TERM_HASH
88
- CSSPool::Terms::Hash.new(
89
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
90
- operator,
91
- LibCroco.location_to_h(self)
92
- )
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,21 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class GList < FFI::Struct
4
- layout(
5
- :data, :pointer,
6
- :next, :pointer,
7
- :prev, :pointer
8
- )
9
-
10
- def to_a
11
- list = [self]
12
- pointer = list.last[:next]
13
- until pointer.null?
14
- list << GList.new(pointer)
15
- pointer = list.last[:next]
16
- end
17
- list.map { |x| x[:data] }
18
- end
19
- end
20
- end
21
- end
@@ -1,78 +0,0 @@
1
- require 'ffi'
2
-
3
- ENV['LIBCROCO'] ||= 'libcroco-0.6'
4
-
5
- module CSSPool
6
- module LibCroco
7
- extend FFI::Library
8
-
9
- retry_times = 0
10
-
11
- retry_places = {
12
- 0 => '/opt/local/lib/libcroco-0.6.dylib',
13
- 1 => '/opt/local/lib/libcroco-0.6.so',
14
- 2 => '/usr/local/lib/libcroco-0.6.dylib',
15
- 3 => '/usr/local/lib/libcroco-0.6.so',
16
- 4 => '/usr/lib/libcroco-0.6.dylib',
17
- 5 => '/usr/lib/libcroco-0.6.so',
18
- }
19
-
20
- begin
21
- ffi_lib ENV['LIBCROCO']
22
- rescue LoadError => ex
23
- if retry_places.key?(retry_times)
24
- ENV['LIBCROCO'] = retry_places[retry_times]
25
- retry_times += 1
26
- retry
27
- end
28
- warn "### Please install libcroco"
29
- warn "### Set LD_LIBRARY_PATH *or* set LIBCROCO to point at libcroco-0.6.dylib"
30
- raise ex
31
- end
32
-
33
- attach_function :cr_doc_handler_new, [], :pointer
34
- attach_function :cr_parser_new_from_buf, [:string, :int, :int, :int], :pointer
35
- attach_function :cr_parser_set_sac_handler, [:pointer, :pointer], :int
36
- attach_function :cr_parser_parse, [:pointer], :int
37
- attach_function :cr_parser_destroy, [:pointer], :void
38
- attach_function :cr_doc_handler_destroy, [:pointer], :void
39
- attach_function :cr_string_peek_raw_str, [:pointer], :pointer
40
- attach_function :cr_simple_sel_compute_specificity, [:pointer], :int
41
-
42
- callback :start_document, [:pointer], :void
43
- callback :end_document, [:pointer], :void
44
- callback :charset, [:pointer, :pointer, :pointer], :void
45
- callback :import_style, [:pointer] * 5, :void
46
- callback :import_style_result, [:pointer] * 5, :void
47
- callback :namespace_declaration, [:pointer] * 4, :void
48
- callback :comment, [:pointer, :pointer], :void
49
- callback :start_selector, [:pointer, :pointer], :void
50
- callback :end_selector, [:pointer, :pointer], :void
51
- callback :property, [:pointer, :pointer, :pointer, :int], :void
52
- callback :start_font_face, [:pointer] * 2, :void
53
- callback :end_font_face, [:pointer], :void
54
- callback :start_media, [:pointer] * 3, :void
55
- callback :end_media, [:pointer] * 2, :void
56
-
57
- def self.location_to_h thing
58
- {
59
- :line => thing[:line],
60
- :column => thing[:column],
61
- :byte_offset => thing[:byte_offset]
62
- }
63
- end
64
- end
65
- end
66
-
67
- require 'csspool/lib_croco/cr_doc_handler'
68
- require 'csspool/lib_croco/cr_pseudo'
69
- require 'csspool/lib_croco/cr_parsing_location'
70
- require 'csspool/lib_croco/glist'
71
- require 'csspool/lib_croco/cr_simple_sel'
72
- require 'csspool/lib_croco/cr_selector'
73
- require 'csspool/lib_croco/cr_additional_sel'
74
- require 'csspool/lib_croco/cr_attr_sel'
75
- require 'csspool/lib_croco/cr_term'
76
- require 'csspool/lib_croco/cr_parser'
77
- require 'csspool/lib_croco/cr_num'
78
- require 'csspool/lib_croco/cr_rgb'
@@ -1,18 +0,0 @@
1
- module CSSPool
2
- module Visitable
3
- def accept target
4
- target.accept self
5
- end
6
-
7
- def to_css
8
- accept Visitors::ToCSS.new
9
- end
10
- alias :to_s :to_css
11
-
12
- def == other
13
- return false unless self.class == other.class
14
-
15
- accept Visitors::Comparable.new other
16
- end
17
- end
18
- end