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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f36f11bbcca2e5fa18b1e9f4720639afddf4fc1
4
- data.tar.gz: a50bd295b6a92e8318589304e380aaf77eba4f92
3
+ metadata.gz: 1f29dc49e7a6c57c613c118de87a4c078db67fce
4
+ data.tar.gz: 2412a0746a375b3bccadf1026cda8aa3382ec27d
5
5
  SHA512:
6
- metadata.gz: 745b5a82150c2d346ec7464a096233e5087b205bd3e74b4ea73b7620c40951001e9e38bed785d515fa8171c9482881c0c7a04551766a0d6fc87183c0e6169bb9
7
- data.tar.gz: 5b1a7ac5c874bca33e1b0c0b0770df9eb2b833eec736d01259ca17958a651def06e88a462d3eaff1a636747988e5457594385170e6d10fa15d3f9aa81fa133c6
6
+ metadata.gz: 656ca627964b0948826378d12ae794f9c69be1f09ba2268d2577ab73fadbb47f1ca4cf424040e0c7112098651b84cff3a8d88b35e6301023683762e6477fcac0
7
+ data.tar.gz: 1b41d903e5f1252f6add7b4831ee73c357676d35e056442190e2f8fdc269b77e07e442af9218e3d51050b71266d8dc7586d446191d83a137a3c82262ddbd2832
@@ -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
- if self.class._event_blocks && callback = self.class._event_blocks[name]
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, :_listeners
48
+ attr_accessor :_event_blocks, :_for_listeners
41
49
 
42
50
  def on_event(name, options = {}, &block)
43
51
  if id = options[:for]
44
- (@_listeners ||= []) << id
52
+ (@_for_listeners ||= []) << id
45
53
  name = :"#{id}_#{name}"
46
54
  end
47
55
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Theme
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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._listeners
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.2
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
@@ -1,13 +0,0 @@
1
- module Theme
2
- class Event
3
- include Eventable
4
-
5
- event :trigger
6
-
7
- def trigger component_name, component_event, data = {}
8
- opts = Hashr.new data
9
- fire_event :trigger, component_name, component_event, opts
10
- data.clear
11
- end
12
- end
13
- end