tao_on_rails 0.8.0 → 0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 723bdfc80962341e3edec02a1e904976a224c91b
4
- data.tar.gz: 3721bd5ecea46051f3af0242d75543f6f14a7e22
3
+ metadata.gz: 7ede1d9a4377793659e2f7249f1c38b349b6d9c4
4
+ data.tar.gz: a161b521a9a106d62cdc0086f141f7d5730c76a3
5
5
  SHA512:
6
- metadata.gz: e32ab3584038acca268311801e487c1f8478e02017aa752714afc146df51688c587deeb18f99caee457a7dda9ebb1731716de3a63ff26cf5f039eae7afc76749
7
- data.tar.gz: 0058328d81ec7984f3f282faddd55a3725a5d0dff75989fa0da66ecbd656337fcb9aa92cd275149361f32eb306c021b9ed6e70ee9eb4c728545c53dbdbe0e3bb
6
+ metadata.gz: 6efff7e9bc759ee2079b2422ffa925bbe709b283a2aa0f95654156982916316c75c7effa25a84ee8ab43df8cff52bb4ea9b9ca7f0fe20d17c58e45d598d7f385
7
+ data.tar.gz: a7b284ea0d976ccc8d1a2281371fd6fd38e45d8f19173255acede3e3fc4e20296d3161838ef5b249e6c556ac74f486aa6163c2bcd5534d0a88f184bfa9d58d27
@@ -53,9 +53,9 @@ class TaoAttributeParser extends TaoModule
53
53
  try
54
54
  JSON.parse value
55
55
  catch e
56
- options.default || {}
56
+ options.default || null
57
57
  else
58
- options.default || {}
58
+ options.default || null
59
59
 
60
60
  @aliasMethod '_parseObject', '_parseHash'
61
61
 
@@ -64,9 +64,9 @@ class TaoAttributeParser extends TaoModule
64
64
  try
65
65
  JSON.parse value
66
66
  catch e
67
- options.default || []
67
+ options.default || null
68
68
  else
69
- options.default || []
69
+ options.default || null
70
70
 
71
71
  _stringifyString: (value, options) ->
72
72
  value.toString()
@@ -109,13 +109,16 @@ TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
109
109
  @taoId = ++count
110
110
  @_init()
111
111
  @initialized = true
112
+ @trigger 'initialized'
112
113
 
113
114
  @_connected()
115
+ @trigger 'connected'
114
116
 
115
117
  disconnectedCallback: ->
116
118
  $ =>
117
119
  @connected = false
118
120
  @_disconnected()
121
+ @trigger 'disconnected'
119
122
 
120
123
  attributeChangedCallback: (name) ->
121
124
  return unless @connected
@@ -136,9 +139,22 @@ TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
136
139
  _attributeChanged: (name) ->
137
140
  @["_#{_.camelCase name}Changed"]?()
138
141
 
142
+ _reflow: ->
143
+ @offsetHeight
144
+ @
145
+
139
146
  beforeCache: ->
140
147
  # called before turbolinks cache pages
141
148
 
149
+ findComponent: (selector, readyCallback) ->
150
+ component = @jq.find(selector).get(0)
151
+ if component.connected
152
+ readyCallback? component
153
+ else
154
+ @one 'connected', selector, ->
155
+ readyCallback? component
156
+ component
157
+
142
158
  on: (args...) ->
143
159
  @jq.on args...
144
160
 
@@ -146,6 +162,9 @@ TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
146
162
  @jq.off args...
147
163
 
148
164
  trigger: (args...) ->
165
+ @jq.trigger(args...)
166
+
167
+ triggerHandler: (args...) ->
149
168
  @jq.triggerHandler(args...)
150
169
 
151
170
  one: (args...) ->
@@ -14,10 +14,10 @@ module Tao
14
14
  @page_id = [class_path, file_name, action].flatten.join('-')
15
15
  if (variants = options[:variants]).any?
16
16
  variants.each do |variant|
17
- template "coffee.erb", File.join("app/assets/javascripts", variant, name.pluralize, "#{action}.coffee")
17
+ template "coffee.erb", File.join("app/assets/javascripts", variant, name.pluralize, "#{action}_page.coffee")
18
18
  end
19
19
  else
20
- template "coffee.erb", File.join('app/assets/javascripts', name.pluralize, "#{action}.coffee")
20
+ template "coffee.erb", File.join('app/assets/javascripts', name.pluralize, "#{action}_page.coffee")
21
21
  end
22
22
  end
23
23
  end
@@ -14,10 +14,10 @@ module Tao
14
14
  @page_id = [class_path, file_name, action].flatten.join('-')
15
15
  if (variants = options[:variants]).any?
16
16
  variants.each do |variant|
17
- template "sass.erb", File.join("app/assets/stylesheets", variant, name.pluralize, "#{action}.scss")
17
+ template "sass.erb", File.join("app/assets/stylesheets", variant, name.pluralize, "#{action}_page.scss")
18
18
  end
19
19
  else
20
- template "sass.erb", File.join('app/assets/stylesheets', name.pluralize, "#{action}.scss")
20
+ template "sass.erb", File.join('app/assets/stylesheets', name.pluralize, "#{action}_page.scss")
21
21
  end
22
22
  end
23
23
  end
@@ -2,29 +2,36 @@ module TaoOnRails
2
2
  module Components
3
3
  class Base
4
4
 
5
- attr_reader :options, :template_path, :view
5
+ attr_reader :options, :template_name, :template_paths, :view
6
6
 
7
7
  def initialize view, options = {}
8
8
  @view = view
9
9
  @options = options
10
- @template_path = @options.delete(:template_path) || self.class.template_path
10
+ @template_name = self.class.template_name.dup
11
+ @template_paths = self.class.template_paths.dup
12
+ @template_paths.unshift(@options.delete(:template_path)) if @options[:template_path].present?
11
13
  end
12
14
 
13
15
  def render &block
14
- if view.lookup_context.exists?(template_path, [], true)
16
+ if template = find_template
15
17
  if block_given?
16
- block_content = view.capture(&block)
17
- view.render layout: template_path, locals: {component: self} do
18
- block_content
18
+ template.render(view, {component: self, block_given: true}) do |*name|
19
+ view._layout_for(*name, &block)
19
20
  end
20
21
  else
21
- view.render partial: template_path, locals: {component: self}
22
+ template.render(view, {component: self})
22
23
  end
23
24
  else
24
25
  view.content_tag self.class.tag_name, nil, options, &block
25
26
  end
26
27
  end
27
28
 
29
+ def translate key
30
+ i18n_scope = self.class.name.underscore.split('/').join('.').gsub(/(.+)_component$/, '\1')
31
+ I18n.t(key, scope: i18n_scope).presence
32
+ end
33
+ alias_method :t, :translate
34
+
28
35
  def self.tag_name
29
36
  @tag_name ||= "#{self.tag_prefix}-#{self.component_name.to_s.dasherize}"
30
37
  end
@@ -39,8 +46,25 @@ module TaoOnRails
39
46
  :tao
40
47
  end
41
48
 
42
- def self.template_path
43
- @template_path ||= "components/#{self.name.underscore.gsub(/(.+)_component$/, '\1')}"
49
+ def self.template_paths
50
+ @template_paths ||= [
51
+ "components/#{self.name.deconstantize.underscore}",
52
+ "#{self.name.deconstantize.underscore}/components"
53
+ ]
54
+ end
55
+
56
+ def self.template_name
57
+ @template_name ||= self.name.demodulize.underscore.gsub(/(.+)_component$/, '\1')
58
+ end
59
+
60
+ private
61
+
62
+ def find_template
63
+ view.lookup_context.find_all(template_name, template_paths, true, template_keys).first
64
+ end
65
+
66
+ def template_keys
67
+ [:component, :block_given]
44
68
  end
45
69
 
46
70
  end
@@ -1,3 +1,3 @@
1
1
  module TaoOnRails
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tao_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siyuan Liu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-18 00:00:00.000000000 Z
12
+ date: 2017-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: turbolinks