glimmer-dsl-css 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +111 -0
  4. data/VERSION +1 -0
  5. data/lib/glimmer-dsl-css.rb +7 -0
  6. data/lib/glimmer/config.rb +22 -0
  7. data/lib/glimmer/css/rule.rb +25 -0
  8. data/lib/glimmer/css/style_sheet.rb +19 -0
  9. data/lib/glimmer/dsl/css/css_expression.rb +21 -0
  10. data/lib/glimmer/dsl/css/dsl.rb +21 -0
  11. data/lib/glimmer/dsl/css/dynamic_property_expression.rb +12 -0
  12. data/lib/glimmer/dsl/css/property_expression.rb +22 -0
  13. data/lib/glimmer/dsl/css/pv_expression.rb +17 -0
  14. data/lib/glimmer/dsl/css/rule_expression.rb +26 -0
  15. data/lib/glimmer/dsl/css/s_expression.rb +26 -0
  16. data/lib/glimmer/dsl/engine.rb +193 -0
  17. data/lib/glimmer/dsl/expression.rb +42 -0
  18. data/lib/glimmer/dsl/expression_handler.rb +48 -0
  19. data/lib/glimmer/dsl/opal/dsl.rb +41 -0
  20. data/lib/glimmer/dsl/opal/label_expression.rb +17 -0
  21. data/lib/glimmer/dsl/opal/property_expression.rb +19 -0
  22. data/lib/glimmer/dsl/opal/shell_expression.rb +19 -0
  23. data/lib/glimmer/dsl/parent_expression.rb +12 -0
  24. data/lib/glimmer/dsl/static_expression.rb +36 -0
  25. data/lib/glimmer/dsl/top_level_expression.rb +7 -0
  26. data/lib/glimmer/dsl/xml/dsl.rb +23 -0
  27. data/lib/glimmer/dsl/xml/html_expression.rb +25 -0
  28. data/lib/glimmer/dsl/xml/meta_expression.rb +23 -0
  29. data/lib/glimmer/dsl/xml/name_space_expression.rb +37 -0
  30. data/lib/glimmer/dsl/xml/node_parent_expression.rb +33 -0
  31. data/lib/glimmer/dsl/xml/tag_expression.rb +29 -0
  32. data/lib/glimmer/dsl/xml/text_expression.rb +22 -0
  33. data/lib/glimmer/dsl/xml/xml_expression.rb +21 -0
  34. data/lib/glimmer/error.rb +6 -0
  35. data/lib/glimmer/invalid_keyword_error.rb +6 -0
  36. data/lib/glimmer/opal/label.rb +31 -0
  37. data/lib/glimmer/opal/shell.rb +34 -0
  38. data/lib/glimmer/xml/depth_first_search_iterator.rb +22 -0
  39. data/lib/glimmer/xml/name_space_visitor.rb +21 -0
  40. data/lib/glimmer/xml/node.rb +75 -0
  41. data/lib/glimmer/xml/node_visitor.rb +13 -0
  42. data/lib/glimmer/xml/xml_visitor.rb +65 -0
  43. metadata +201 -0
@@ -0,0 +1,21 @@
1
+ require 'glimmer/dsl/xml/node_parent_expression'
2
+ require 'glimmer/dsl/expression'
3
+ require 'glimmer/xml/node'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module XML
8
+ class XmlExpression < Expression
9
+ include NodeParentExpression
10
+
11
+ def can_interpret?(parent, keyword, *args, &block)
12
+ parent.is_a?(Glimmer::XML::Node)
13
+ end
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Glimmer
2
+ # Represents Glimmer errors that occur due to invalid use of Glimmer
3
+ # without handing control flow back to original method_missing
4
+ class Error < RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Glimmer
2
+ # Represents Glimmer errors that occur due to invalid use of Glimmer
3
+ # without handing control flow back to original method_missing
4
+ class InvalidKeywordError < RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ module Glimmer
2
+ module Opal
3
+ class Label
4
+ attr_reader :text
5
+
6
+ def initialize(parent, args)
7
+ @parent = parent
8
+ @args = args
9
+ @parent.add_child(self)
10
+ end
11
+
12
+ def text=(value)
13
+ @text = value
14
+ redraw
15
+ end
16
+
17
+ def redraw
18
+ old_dom = @dom
19
+ @dom = nil
20
+ old_dom.replace dom
21
+ end
22
+
23
+ def dom
24
+ label_text = @text
25
+ @dom ||= DOM {
26
+ label label_text
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ module Glimmer
2
+ module Opal
3
+ class Shell
4
+ def initialize(args)
5
+ @args = args
6
+ @children = []
7
+ $document.ready do
8
+ $document.body.replace(dom)
9
+ end
10
+ end
11
+
12
+ def text
13
+ $document.title
14
+ end
15
+
16
+ def text=(value)
17
+ $document.title = value
18
+ end
19
+
20
+ def add_child(child)
21
+ return if @children.include?(child)
22
+ @children << child
23
+ dom << child.dom
24
+ end
25
+
26
+ def dom
27
+ @dom ||= DOM {
28
+ body {
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ require 'glimmer/xml/node'
2
+
3
+ module Glimmer
4
+ module XML
5
+ class DepthFirstSearchIterator
6
+ def initialize(node, node_visitor)
7
+ @node = node
8
+ @node_visitor = node_visitor
9
+ end
10
+
11
+ def iterate
12
+ process(@node)
13
+ end
14
+
15
+ def process(node)
16
+ @node_visitor.process_before_children(node)
17
+ node.children.each { |child| process(child) } if node.is_a?(Node)
18
+ @node_visitor.process_after_children(node)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require "glimmer/xml/node_visitor"
2
+
3
+ module Glimmer
4
+ module XML
5
+ class NameSpaceVisitor < NodeVisitor
6
+
7
+ def initialize(name_space_name)
8
+ @name_space_name = name_space_name
9
+ end
10
+
11
+ def process_before_children(node)
12
+ return if node.is_a?(String)
13
+ node.name_space = Node.new(nil, @name_space_name, nil) if node and !node.name_space
14
+ end
15
+
16
+ def process_after_children(node)
17
+ #NOOP
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ require 'glimmer'
2
+ require 'glimmer/xml/depth_first_search_iterator'
3
+ require 'glimmer/xml/xml_visitor'
4
+
5
+ module Glimmer
6
+ module XML
7
+ class Node
8
+ include Glimmer
9
+
10
+ attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
11
+
12
+ def initialize(parent, name, attributes, &contents)
13
+ @is_name_space = false
14
+ @children = []
15
+ @parent = parent
16
+ if attributes.is_a?(Array)
17
+ attributes = attributes.compact
18
+ hash_attributes = attributes.last.is_a?(Hash) ? attributes.delete(attributes.last) : {}
19
+ hash_attributes = attributes.reduce(hash_attributes) do |hash, attribute|
20
+ hash.merge(attribute => nil)
21
+ end
22
+ attributes = hash_attributes
23
+ end
24
+ if (parent and parent.is_name_space)
25
+ @name_space = parent
26
+ @parent = @name_space.parent
27
+ end
28
+ @parent.children << self if @parent
29
+ @name = name
30
+ @contents = contents
31
+ @attributes = attributes
32
+ if @attributes
33
+ @attributes.each_key do |attribute|
34
+ if attribute.is_a?(Node)
35
+ attribute.is_attribute = true
36
+ attribute.parent.children.delete(attribute) if attribute.parent
37
+ attribute.parent = nil #attributes do not usually have parents
38
+ end
39
+ end
40
+ Glimmer::Config.logger&.debug(attributes)
41
+ end
42
+ end
43
+
44
+ def method_missing(symbol, *args, &block)
45
+ @is_name_space = true
46
+ parent.children.delete(self) if parent
47
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::HtmlExpression.new) {@tag = super}
48
+ @tag
49
+ end
50
+
51
+ def to_xml
52
+ xml_visitor = XmlVisitor.new
53
+ DepthFirstSearchIterator.new(self, xml_visitor).iterate
54
+ xml_visitor.document
55
+ end
56
+ alias to_html to_xml
57
+ alias to_s to_xml
58
+
59
+ def text_command(text)
60
+ "text \"#{text}\""
61
+ end
62
+
63
+ def rubyize(text)
64
+ text = text.gsub(/[}]/, '"}')
65
+ text = text.gsub(/[{]/, '{"')
66
+ text = text.gsub(/[#]/, '')
67
+ end
68
+
69
+ #override Object default id method and route it to Glimmer engine
70
+ def id
71
+ method_missing(:id)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,13 @@
1
+ module Glimmer
2
+ module XML
3
+ class NodeVisitor
4
+ def process_before_children
5
+ raise "must be implemented by a class"
6
+ end
7
+
8
+ def process_after_children
9
+ raise "must be implemented by a class"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ require "glimmer/xml/node_visitor"
2
+ require "glimmer/xml/node"
3
+
4
+ module Glimmer
5
+ module XML
6
+ class XmlVisitor < NodeVisitor
7
+
8
+ attr_reader :document
9
+
10
+ def initialize
11
+ @document = ""
12
+ end
13
+
14
+ def process_before_children(node)
15
+ if (!node.is_a?(Glimmer::XML::Node))
16
+ @document += node.to_s
17
+ return
18
+ end
19
+ begin_open_tag(node)
20
+ append_attributes(node) if node.attributes
21
+ end_open_tag(node)
22
+ end
23
+
24
+ def process_after_children(node)
25
+ return if (!node.is_a?(Glimmer::XML::Node))
26
+ append_close_tag(node)
27
+ end
28
+
29
+ def begin_open_tag(node)
30
+ @document += "<"
31
+ @document += "#{node.name_space.name}:" if node.name_space
32
+ @document += node.name
33
+ end
34
+
35
+ def end_open_tag(node)
36
+ if (node.contents)
37
+ @document += ">"
38
+ else
39
+ @document += " " if node.attributes.keys.size > 0
40
+ @document += "/>"
41
+ end
42
+ end
43
+
44
+ def append_close_tag(node)
45
+ if (node.contents)
46
+ @document += "</"
47
+ @document += "#{node.name_space.name}:" if node.name_space
48
+ @document += "#{node.name}>"
49
+ end
50
+ end
51
+
52
+ def append_attributes(node)
53
+ Glimmer::Config.logger&.debug "Take 3"
54
+ Glimmer::Config.logger&.debug(node.attributes)
55
+ node.attributes.each do |attribute, value|
56
+ attribute_name = attribute
57
+ attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
58
+ @document += " #{attribute_name}"
59
+ @document += "=\"#{value}\"" unless value.nil?
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glimmer-dsl-css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AndyMaleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.9.0
19
+ name: glimmer
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.5.0
33
+ name: rspec-mocks
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.5.0
47
+ name: rspec
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.8.1
61
+ name: puts_debuggerer
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 10.1.0
75
+ - - "<"
76
+ - !ruby/object:Gem::Version
77
+ version: 14.0.0
78
+ name: rake
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 10.1.0
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 14.0.0
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.3.9
95
+ - - "<"
96
+ - !ruby/object:Gem::Version
97
+ version: 3.0.0
98
+ name: jeweler
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 2.3.9
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: 3.0.0
109
+ - !ruby/object:Gem::Dependency
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 6.2.1
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: 7.0.0
118
+ name: rdoc
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 6.2.1
126
+ - - "<"
127
+ - !ruby/object:Gem::Version
128
+ version: 7.0.0
129
+ description: Glimmer DSL for CSS (Cascading Style Sheets)
130
+ email: andy.am@gmail.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.md
136
+ files:
137
+ - LICENSE.txt
138
+ - README.md
139
+ - VERSION
140
+ - lib/glimmer-dsl-css.rb
141
+ - lib/glimmer/config.rb
142
+ - lib/glimmer/css/rule.rb
143
+ - lib/glimmer/css/style_sheet.rb
144
+ - lib/glimmer/dsl/css/css_expression.rb
145
+ - lib/glimmer/dsl/css/dsl.rb
146
+ - lib/glimmer/dsl/css/dynamic_property_expression.rb
147
+ - lib/glimmer/dsl/css/property_expression.rb
148
+ - lib/glimmer/dsl/css/pv_expression.rb
149
+ - lib/glimmer/dsl/css/rule_expression.rb
150
+ - lib/glimmer/dsl/css/s_expression.rb
151
+ - lib/glimmer/dsl/engine.rb
152
+ - lib/glimmer/dsl/expression.rb
153
+ - lib/glimmer/dsl/expression_handler.rb
154
+ - lib/glimmer/dsl/opal/dsl.rb
155
+ - lib/glimmer/dsl/opal/label_expression.rb
156
+ - lib/glimmer/dsl/opal/property_expression.rb
157
+ - lib/glimmer/dsl/opal/shell_expression.rb
158
+ - lib/glimmer/dsl/parent_expression.rb
159
+ - lib/glimmer/dsl/static_expression.rb
160
+ - lib/glimmer/dsl/top_level_expression.rb
161
+ - lib/glimmer/dsl/xml/dsl.rb
162
+ - lib/glimmer/dsl/xml/html_expression.rb
163
+ - lib/glimmer/dsl/xml/meta_expression.rb
164
+ - lib/glimmer/dsl/xml/name_space_expression.rb
165
+ - lib/glimmer/dsl/xml/node_parent_expression.rb
166
+ - lib/glimmer/dsl/xml/tag_expression.rb
167
+ - lib/glimmer/dsl/xml/text_expression.rb
168
+ - lib/glimmer/dsl/xml/xml_expression.rb
169
+ - lib/glimmer/error.rb
170
+ - lib/glimmer/invalid_keyword_error.rb
171
+ - lib/glimmer/opal/label.rb
172
+ - lib/glimmer/opal/shell.rb
173
+ - lib/glimmer/xml/depth_first_search_iterator.rb
174
+ - lib/glimmer/xml/name_space_visitor.rb
175
+ - lib/glimmer/xml/node.rb
176
+ - lib/glimmer/xml/node_visitor.rb
177
+ - lib/glimmer/xml/xml_visitor.rb
178
+ homepage: http://github.com/AndyObtiva/glimmer-dsl-css
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubygems_version: 3.0.6
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Glimmer DSL for CSS
201
+ test_files: []