theme 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/theme/component.rb +7 -2
- data/lib/theme/events.rb +11 -3
- data/lib/theme/middleware.rb +6 -0
- data/lib/theme/version.rb +1 -1
- data/lib/theme.rb +2 -2
- metadata +1 -2
- data/lib/theme/event.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f29dc49e7a6c57c613c118de87a4c078db67fce
|
4
|
+
data.tar.gz: 2412a0746a375b3bccadf1026cda8aa3382ec27d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656ca627964b0948826378d12ae794f9c69be1f09ba2268d2577ab73fadbb47f1ca4cf424040e0c7112098651b84cff3a8d88b35e6301023683762e6477fcac0
|
7
|
+
data.tar.gz: 1b41d903e5f1252f6add7b4831ee73c357676d35e056442190e2f8fdc269b77e07e442af9218e3d51050b71266d8dc7586d446191d83a137a3c82262ddbd2832
|
data/lib/theme/component.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
require 'hashr'
|
3
3
|
|
4
|
-
Hashr.raise_missing_keys = true
|
5
|
-
|
6
4
|
module Theme
|
7
5
|
class Component < SimpleDelegator
|
8
6
|
include Theme::Events
|
@@ -91,6 +89,13 @@ module Theme
|
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
92
|
+
def partial template, locals = {}
|
93
|
+
locals[:partial] = template
|
94
|
+
resp = render locals
|
95
|
+
resp
|
96
|
+
end
|
97
|
+
|
98
|
+
|
94
99
|
def set_locals options
|
95
100
|
options.to_h.each do |key, value|
|
96
101
|
(class << self; self; end).send(:attr_accessor, key.to_sym)
|
data/lib/theme/events.rb
CHANGED
@@ -21,7 +21,15 @@ module Theme
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def trigger(name, options = {})
|
24
|
-
|
24
|
+
callback = false
|
25
|
+
|
26
|
+
if respond_to? name
|
27
|
+
callback = name
|
28
|
+
elsif self.class._event_blocks
|
29
|
+
callback = self.class._event_blocks[name]
|
30
|
+
end
|
31
|
+
|
32
|
+
if callback
|
25
33
|
if callback.is_a? Proc
|
26
34
|
callback.call options
|
27
35
|
else
|
@@ -37,11 +45,11 @@ module Theme
|
|
37
45
|
end
|
38
46
|
|
39
47
|
module Macros
|
40
|
-
attr_accessor :_event_blocks, :
|
48
|
+
attr_accessor :_event_blocks, :_for_listeners
|
41
49
|
|
42
50
|
def on_event(name, options = {}, &block)
|
43
51
|
if id = options[:for]
|
44
|
-
(@
|
52
|
+
(@_for_listeners ||= []) << id
|
45
53
|
name = :"#{id}_#{name}"
|
46
54
|
end
|
47
55
|
|
data/lib/theme/middleware.rb
CHANGED
@@ -48,11 +48,17 @@ module Theme
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def render_component
|
51
|
+
res.headers['Content-Type'] = 'Content-Type: text/javascript; charset=UTF-8'
|
52
|
+
|
51
53
|
app.instance_variable_set :@res, res
|
52
54
|
app.instance_variable_set :@req, req
|
55
|
+
app.instance_variable_set :@env, req.env
|
56
|
+
|
53
57
|
name = req.params['component_name'].to_sym
|
54
58
|
event = req.params['component_event'].to_sym
|
59
|
+
|
55
60
|
app.theme_components[name].trigger event, Hashr.new(req.params)
|
61
|
+
|
56
62
|
res.finish
|
57
63
|
end
|
58
64
|
end
|
data/lib/theme/version.rb
CHANGED
data/lib/theme.rb
CHANGED
@@ -130,11 +130,11 @@ module Theme
|
|
130
130
|
Theme.config.components.each do |name, klass|
|
131
131
|
component = Object.const_get(klass).new self
|
132
132
|
components[name] = component
|
133
|
-
component.instance_variable_set :@id
|
133
|
+
component.instance_variable_set :@id, name
|
134
134
|
end
|
135
135
|
|
136
136
|
components.each do |name, component|
|
137
|
-
if listeners = component.class.
|
137
|
+
if listeners = component.class._for_listeners
|
138
138
|
listeners.each do |id|
|
139
139
|
if c = components[id.to_sym]
|
140
140
|
c.add_listener component
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- lib/theme/assets/middleware.rb
|
100
100
|
- lib/theme/assets/render.rb
|
101
101
|
- lib/theme/component.rb
|
102
|
-
- lib/theme/event.rb
|
103
102
|
- lib/theme/events.rb
|
104
103
|
- lib/theme/file.rb
|
105
104
|
- lib/theme/mab.rb
|
data/lib/theme/event.rb
DELETED