simple_style_sheet 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.0 (August 25, 2012)
2
+ Selectors can now be written as symbols.
3
+
1
4
  0.0.2 (February 26, 2012)
2
5
  Delegated selector-related functionality to SimpleSelector gem.
3
6
 
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
- SimpleStyleSheet
2
- ================
1
+ simple_style_sheet
2
+ ==================
3
3
 
4
- SimpleStyleSheet is a Ruby gem that **parses a CSS-like Hash style sheet** and then **allows searching for property values of given HTML-like tags**. Tag and property names, as well as their meaning, are up to the gem user.
4
+ simple_style_sheet is a Ruby gem that **parses a CSS-like Hash style sheet** and then **allows searching for property values of given HTML-like tags**. Tag and property names, as well as their meaning, are up to the gem user.
5
5
 
6
6
  Usage and details
7
7
  -----------------
8
8
 
9
9
  ### 1. Style sheet preparation
10
10
 
11
- The style sheet is just a CSS-like Hash object. Its keys are either property names or selectors, and values are either property values or nested Hash objects.
11
+ The style sheet is just a CSS-like Hash object. Its keys are either selectors or property names, and values are either property values or nested Hash objects.
12
12
 
13
13
  ##### Property names
14
14
 
15
- Property names can be objects of any class and their meaning is up to the user. Most often, they would be String or Symbol instances with content that is some formatting-related property name, like "background-color".
15
+ Property names can be objects of any class and their meaning is up to the user. Most often, they would be String or Symbol instances with content that is some formatting-related property name, like `:background_color`.
16
16
 
17
17
  ##### Property values
18
18
 
@@ -20,20 +20,20 @@ The values can also be any objects, except for Hash objects, which are interpret
20
20
 
21
21
  ##### Selectors
22
22
 
23
- A selector is a String object that contains one or more custom **tag names**, **ids** and **class names**. For example: `#content message.success`.
23
+ A selector is a String or Symbol object that contains one or more custom **tag names**, **ids** and **class names**. For example: `#content message.success`.
24
24
 
25
25
  ##### A style sheet example
26
26
 
27
27
  ```ruby
28
28
  style_sheet = {
29
- "foreground-color" => :white,
30
- "background-color" => :blue,
29
+ foreground_color: :white,
30
+ background_color: :blue,
31
31
 
32
32
  "#content message.success" => {
33
- "background-color" => :green,
33
+ background_color: :green,
34
34
 
35
35
  "number" => {
36
- "background-color" => :inherit
36
+ foreground_color: :inherit
37
37
  }
38
38
  }
39
39
  }
@@ -55,9 +55,10 @@ Tag objects represent tags in a HTML-like structure. As a tag, any object can be
55
55
  Tag = Struct.new(:name, :id, :class_names, :parent)
56
56
 
57
57
  # Tag objects corresponding to the structure:
58
- # <section id="content"><message class="success">...</message></section>
59
- content_tag = Tag.new("section", "content", [], nil)
60
- message_tag = Tag.new("message", nil, ["success"], content_tag)
58
+ # <section id="content"><message class="success"><number>...</number></message></section>
59
+ content_tag = Tag.new("section", "content", [] , nil)
60
+ message_tag = Tag.new("message", nil , ["success"], content_tag)
61
+ number_tag = Tag.new("number" , nil , [] , message_tag)
61
62
  ```
62
63
 
63
64
  ### 4. Getting property value for a given tag
@@ -65,39 +66,42 @@ Tag objects represent tags in a HTML-like structure. As a tag, any object can be
65
66
  Now, a property value for a given tag can be obtained:
66
67
 
67
68
  ```ruby
68
- style_sheet_handler.value_for(message_tag, "background-color")
69
+ style_sheet_handler.value_for(message_tag, :foreground_color)
70
+ => :white
71
+
72
+ style_sheet_handler.value_for(message_tag, :background_color)
69
73
  => :green
70
74
 
71
- style_sheet_handler.value_for(message_tag, "foreground-color")
72
- => :white
75
+ style_sheet_handler.value_for( number_tag, :foreground_color)
76
+ => :inherit
73
77
  ```
74
78
 
75
- The #value_for method looks in the style sheet for selectors that match a given tag. If more than one matching selector is found, the one with highest specificity is used (more details below). Then the value it points to for given property name is returned.
79
+ The `#value_for` method looks in the style sheet for selectors that match the given tag. If more than one matching selector is found, the one with highest specificity is used (more details below). Then it returns the value it points to for given property name.
76
80
 
77
81
  ### 5. Getting top-level property value
78
82
 
79
- The #value_for method, when called without the tag argument, returns top-level property value (defined in the style sheet without a selector), which may be interpreted as default one or as a value for text not included in any tags. For example:
83
+ The `#value_for` method, when called without the tag argument, returns top-level property value (defined in the style sheet without a selector), which may be interpreted as a default one or as a value for text not included in any tags. For example:
80
84
 
81
85
  ```ruby
82
- style_sheet_handler.value_for("background-color")
86
+ style_sheet_handler.value_for(:background_color)
83
87
  => :blue
84
88
  ```
85
89
 
86
90
  Selector specificity
87
91
  --------------------
88
92
 
89
- Selector specificity information can be found in the description of [SimpleSelector](http://github.com/jacekmikrut/simple_selector) Ruby gem.
93
+ Selector specificity information can be found in the description of [simple_selector](http://github.com/jacekmikrut/simple_selector) Ruby gem.
90
94
 
91
- Property name translator
92
- ------------------------
95
+ Property name translator (optional)
96
+ -----------------------------------
93
97
 
94
- A property name translator allows using multiple names (or aliases) for a single property name. For example, property named "background-color" can have aliases "background", "bg-color" etc.
98
+ A property name translator allows using multiple names (aliases) for a single property name. For example, property named `:background_color` can have aliases `:background`, `:bg_color` etc.
95
99
 
96
- The translator, that is supposed to be provided by the gem user, should respond to :translate method and return the translation for a given property name, for example:
100
+ The translator, that is supposed to be provided by the gem user, should respond to `:translate` method and return the translation for given property name, for example:
97
101
 
98
102
  ```ruby
99
- property_name_translator.translate("bg-color")
100
- => "background-color"
103
+ property_name_translator.translate(:bg_color)
104
+ => :background_color
101
105
  ```
102
106
 
103
107
  In order to use the translator, it should be passed as the second argument to SimpleStyleSheet::Handler.new method:
@@ -109,7 +113,7 @@ In order to use the translator, it should be passed as the second argument to Si
109
113
  Installation
110
114
  ------------
111
115
 
112
- As a Ruby gem, SimpleStyleSheet can be installed either by running
116
+ As a Ruby gem, simple_style_sheet can be installed either by running
113
117
 
114
118
  ```bash
115
119
  gem install simple_style_sheet
@@ -31,7 +31,7 @@ module SimpleStyleSheet
31
31
 
32
32
  case value
33
33
  when Hash
34
- populate(value, selector + key)
34
+ populate(value, selector + key.to_s)
35
35
  else
36
36
  property_name = final_property_name(key)
37
37
 
@@ -1,3 +1,3 @@
1
1
  module SimpleStyleSheet
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-26 00:00:00.000000000Z
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simple_selector
16
- requirement: &83580310 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83580310
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &83580040 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '2.0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *83580040
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
36
46
  description: Parses a CSS-like Hash style sheet and allows searching for property
37
47
  values of HTML-like tags. Tag and property names, as well as their meaning, are
38
48
  up to the gem user.
@@ -41,9 +51,9 @@ executables: []
41
51
  extensions: []
42
52
  extra_rdoc_files: []
43
53
  files:
44
- - lib/simple_style_sheet.rb
45
- - lib/simple_style_sheet/handler.rb
46
54
  - lib/simple_style_sheet/version.rb
55
+ - lib/simple_style_sheet/handler.rb
56
+ - lib/simple_style_sheet.rb
47
57
  - README.md
48
58
  - LICENSE
49
59
  - Changelog
@@ -67,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
77
  version: '0'
68
78
  requirements: []
69
79
  rubyforge_project:
70
- rubygems_version: 1.8.12
80
+ rubygems_version: 1.8.24
71
81
  signing_key:
72
82
  specification_version: 3
73
83
  summary: Parses a CSS-like Hash style sheet and allows searching for property values