simple_style_sheet 0.0.1 → 0.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.
data/Changelog CHANGED
@@ -1,2 +1,5 @@
1
+ 0.0.2 (February 26, 2012)
2
+ Delegated selector-related functionality to SimpleSelector gem.
3
+
1
4
  0.0.1 (February 21, 2012)
2
5
  Initial release.
data/README.md CHANGED
@@ -86,22 +86,7 @@ The #value_for method, when called without the tag argument, returns top-level p
86
86
  Selector specificity
87
87
  --------------------
88
88
 
89
- In order to return a property value for a given tag, search for the matching selector of highest specificity is performed.
90
-
91
- The specificity of each selector is calculated according to rules similar to the standard CSS rules.
92
-
93
- The specificity is four numbers: **a,b,c,d**.
94
-
95
- **The rules respected by this gem are**:
96
-
97
- * **a** is always 0;
98
- * **b** is the number of ID attributes in the selector;
99
- * **c** is the number of class names in the selector;
100
- * **d** is the number of tag names in the selector.
101
-
102
- For example, a selector `tag#id1.class1 #id2.class2.class3` has specificity equal to `0,2,3,1`.
103
-
104
- Two selector specificities are compared by succesively comparing their corresponding numbers, from left to right.
89
+ Selector specificity information can be found in the description of [SimpleSelector](http://github.com/jacekmikrut/simple_selector) Ruby gem.
105
90
 
106
91
  Property name translator
107
92
  ------------------------
@@ -42,7 +42,7 @@ module SimpleStyleSheet
42
42
  end
43
43
 
44
44
  def new_selector
45
- Selector.new
45
+ SimpleSelector.new
46
46
  end
47
47
 
48
48
  def final_property_name(property_name)
@@ -1,3 +1,3 @@
1
1
  module SimpleStyleSheet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,8 +1,7 @@
1
1
  require "simple_style_sheet/version"
2
2
 
3
- require "simple_style_sheet/selector_specificity"
4
- require "simple_style_sheet/selector_segment"
5
- require "simple_style_sheet/selector"
3
+ require "simple_selector"
4
+
6
5
  require "simple_style_sheet/handler"
7
6
 
8
7
  module SimpleStyleSheet
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_style_sheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000Z
12
+ date: 2012-02-26 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: simple_selector
16
+ requirement: &83580310 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *83580310
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &74598880 !ruby/object:Gem::Requirement
27
+ requirement: &83580040 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ~>
@@ -21,7 +32,7 @@ dependencies:
21
32
  version: '2.0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *74598880
35
+ version_requirements: *83580040
25
36
  description: Parses a CSS-like Hash style sheet and allows searching for property
26
37
  values of HTML-like tags. Tag and property names, as well as their meaning, are
27
38
  up to the gem user.
@@ -33,9 +44,6 @@ files:
33
44
  - lib/simple_style_sheet.rb
34
45
  - lib/simple_style_sheet/handler.rb
35
46
  - lib/simple_style_sheet/version.rb
36
- - lib/simple_style_sheet/selector.rb
37
- - lib/simple_style_sheet/selector_segment.rb
38
- - lib/simple_style_sheet/selector_specificity.rb
39
47
  - README.md
40
48
  - LICENSE
41
49
  - Changelog
@@ -1,63 +0,0 @@
1
- module SimpleStyleSheet
2
- class Selector
3
-
4
- def initialize(string=nil)
5
- @segments = []
6
- @specificity = SelectorSpecificity.new
7
- concat(string) unless string.nil?
8
- end
9
-
10
- attr_reader :specificity
11
-
12
- def concat(string)
13
- string.scan(/[\w.#]+/).map { |s| SelectorSegment.new(s) }.each do |segment|
14
- @segments << segment
15
- @specificity += segment.specificity
16
- end
17
- self
18
- end
19
-
20
- def +(string)
21
- duplicate.concat(string)
22
- end
23
-
24
- def match?(tag)
25
- return true if @segments.none?
26
- return false unless @segments.last.match?(tag)
27
-
28
- index = @segments.size - 2
29
- current_tag = tag
30
-
31
- while index >= 0 && current_tag = current_tag.parent
32
- if @segments[index].match?(current_tag)
33
- index -= 1
34
- next
35
- end
36
- end
37
- index == -1
38
- end
39
-
40
- def empty?
41
- @segments.none?
42
- end
43
-
44
- def to_s
45
- @segments.map { |segment| segment.to_s }.join(" ")
46
- end
47
-
48
- def inspect
49
- "#<#{self.class} #{to_s.inspect}>"
50
- end
51
-
52
- def ==(other)
53
- to_s == other.to_s
54
- end
55
-
56
- def duplicate
57
- d = dup
58
- d.instance_variable_set( "@segments", @segments.dup)
59
- d.instance_variable_set("@specificity", @specificity.dup)
60
- d
61
- end
62
- end
63
- end
@@ -1,38 +0,0 @@
1
- module SimpleStyleSheet
2
- class SelectorSegment
3
-
4
- def initialize(string)
5
- @tag_name = string.lstrip.slice(/^\w+/)
6
- @id = string.slice(/(?<=\#)\w+/)
7
- @class_names = string.scan(/(?<=\.)\w+/)
8
- end
9
-
10
- attr_reader :tag_name, :id, :class_names
11
-
12
- def specificity
13
- @specificity ||= SelectorSpecificity.new(
14
- 0,
15
- id ? 1 : 0,
16
- class_names.count,
17
- tag_name ? 1 : 0
18
- )
19
- end
20
-
21
- def match?(tag)
22
- return false if tag_name && tag_name != tag.name
23
- return false if id && id != tag.id
24
- return false if (class_names - tag.class_names).any?
25
- true
26
- end
27
-
28
- def to_s
29
- "#{tag_name}" +
30
- (id ? "##{id}" : "") +
31
- class_names.map { |class_name| ".#{class_name}" }.join
32
- end
33
-
34
- def inspect
35
- "#<#{self.class} #{to_s.inspect}>"
36
- end
37
- end
38
- end
@@ -1,32 +0,0 @@
1
- module SimpleStyleSheet
2
- class SelectorSpecificity
3
-
4
- include Comparable
5
-
6
- def initialize(a=0, b=0, c=0, d=0)
7
- @a, @b, @c, @d = a, b, c, d
8
- end
9
-
10
- attr_accessor :a, :b, :c, :d
11
-
12
- def <=>(other)
13
- [:a, :b, :c, :d].each do |name|
14
- result = send(name) <=> other.send(name)
15
- return result unless result == 0
16
- end
17
- 0
18
- end
19
-
20
- def +(other)
21
- self.class.new(a + other.a, b + other.b, c + other.c, d + other.d)
22
- end
23
-
24
- def to_s
25
- "#{a},#{b},#{c},#{d}"
26
- end
27
-
28
- def inspect
29
- "#<#{self.class} #{to_s.inspect}>"
30
- end
31
- end
32
- end