tao_on_rails 0.10.0 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/tao/component/component_generator.rb +2 -12
  3. data/lib/generators/tao/install/install_generator.rb +11 -9
  4. data/lib/generators/tao/install/templates/app/views/layouts/application.html.erb +0 -1
  5. data/lib/tao_on_rails/action_view/helpers.rb +1 -1
  6. data/lib/tao_on_rails/components/base.rb +10 -3
  7. data/lib/tao_on_rails/engine.rb +0 -4
  8. data/lib/tao_on_rails/version.rb +1 -1
  9. metadata +7 -133
  10. data/lib/assets/javascripts/tao/application.coffee +0 -86
  11. data/lib/assets/javascripts/tao/attribute_manager.coffee +0 -94
  12. data/lib/assets/javascripts/tao/component.coffee +0 -175
  13. data/lib/assets/javascripts/tao/helpers.coffee +0 -34
  14. data/lib/assets/javascripts/tao/index.coffee +0 -14
  15. data/lib/assets/javascripts/tao/module.coffee +0 -93
  16. data/lib/assets/javascripts/tao/page.coffee +0 -9
  17. data/lib/assets/stylesheets/tao.scss +0 -3
  18. data/lib/generators/tao/assets/USAGE +0 -18
  19. data/lib/generators/tao/assets/assets_generator.rb +0 -8
  20. data/lib/generators/tao/channel/USAGE +0 -9
  21. data/lib/generators/tao/channel/channel_generator.rb +0 -17
  22. data/lib/generators/tao/channel/templates/channel.coffee.erb +0 -20
  23. data/lib/generators/tao/channel/templates/channel.rb.erb +0 -13
  24. data/lib/generators/tao/coffee/USAGE +0 -15
  25. data/lib/generators/tao/coffee/coffee_generator.rb +0 -27
  26. data/lib/generators/tao/coffee/templates/coffee.erb +0 -14
  27. data/lib/generators/tao/component/templates/component.coffee.erb +0 -5
  28. data/lib/generators/tao/component/templates/component.scss.erb +0 -3
  29. data/lib/generators/tao/controller/USAGE +0 -8
  30. data/lib/generators/tao/controller/controller_generator.rb +0 -20
  31. data/lib/generators/tao/controller/templates/controller.rb.erb +0 -57
  32. data/lib/generators/tao/locale/USAGE +0 -11
  33. data/lib/generators/tao/locale/locale_generator.rb +0 -34
  34. data/lib/generators/tao/locale/templates/model.yml.erb +0 -7
  35. data/lib/generators/tao/sass/USAGE +0 -15
  36. data/lib/generators/tao/sass/sass_generator.rb +0 -27
  37. data/lib/generators/tao/sass/templates/sass.erb +0 -3
  38. data/lib/generators/tao/scaffold/USAGE +0 -22
  39. data/lib/generators/tao/scaffold/scaffold_generator.rb +0 -16
  40. data/lib/generators/tao/view/USAGE +0 -9
  41. data/lib/generators/tao/view/templates/create.js.coffee +0 -5
  42. data/lib/generators/tao/view/templates/destroy.js.coffee +0 -2
  43. data/lib/generators/tao/view/templates/edit.html.erb +0 -1
  44. data/lib/generators/tao/view/templates/index.html.erb +0 -1
  45. data/lib/generators/tao/view/templates/new.html.erb +0 -1
  46. data/lib/generators/tao/view/templates/show.html.erb +0 -1
  47. data/lib/generators/tao/view/templates/update.js.coffee +0 -5
  48. data/lib/generators/tao/view/view_generator.rb +0 -38
  49. data/vendor/assets/javascripts/polyfills/custom-elements.js +0 -68
  50. data/vendor/assets/javascripts/polyfills/index.coffee +0 -7
  51. data/vendor/assets/javascripts/polyfills/native-shim.coffee +0 -117
@@ -1,175 +0,0 @@
1
- #= require ./attribute_manager
2
-
3
- components = {}
4
-
5
- TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
6
- return components[superClassName] if components[superClassName]
7
-
8
- class ComponentClass
9
-
10
- # coffee's inheritance code is not compatible with custom elements
11
- superClass = window[superClassName]
12
-
13
- @prototype = Object.create superClass.prototype,
14
- constructor:
15
- value: @
16
- enumerable: false
17
- writable: true
18
- configurable: true
19
-
20
- if Object.setPrototypeOf?
21
- Object.setPrototypeOf @, superClass
22
- else
23
- @__proto__ = superClass
24
-
25
-
26
- count = 0
27
-
28
- @extend: (obj) ->
29
- obj = obj.call(@) if _.isFunction obj
30
- return unless obj and typeof obj == 'object'
31
-
32
- for key, val of obj when key not in ['included', 'extended']
33
- @[key] = val
34
-
35
- obj.extended?.call(@)
36
- @
37
-
38
- @include: (obj) ->
39
- obj = obj.call(@) if _.isFunction obj
40
- return unless obj and typeof obj == 'object'
41
-
42
- for key, val of obj when key not in ['included', 'extended']
43
- @::[key] = val
44
-
45
- obj.included?.call(@)
46
- @
47
-
48
- @get: (attributeName, getMethod) ->
49
- Object.defineProperty @prototype, attributeName,
50
- get: getMethod
51
- configurable: true
52
-
53
- @set: (attributeName, setMethod) ->
54
- Object.defineProperty @prototype, attributeName,
55
- set: setMethod
56
- configurable: true
57
-
58
- @attribute: (names..., options = {}) ->
59
- unless typeof options == 'object'
60
- names.push(options)
61
- options = {}
62
-
63
- names.forEach (name) =>
64
- attrName = _.kebabCase(name)
65
-
66
- @get name, ->
67
- Tao.AttributeManager.getAttribute @, attrName, options
68
-
69
- @set name, (val) ->
70
- return if @_beforeAttributeChanged(attrName, val) == false
71
- Tao.AttributeManager.setAttribute @, attrName, val, options
72
-
73
- @observedAttributes.push(attrName) if options.observe
74
-
75
- @_tag: 'tao-component'
76
-
77
- @tag: (tag) ->
78
- @_tag = tag unless _.isUndefined tag
79
- @_tag
80
-
81
- @register: (componentClass) ->
82
- return unless componentClass.tag() && window.customElements
83
- customElements.define componentClass.tag(), componentClass
84
-
85
- @observedAttributes: []
86
-
87
- @get 'jq', ->
88
- $(@)
89
-
90
- @attribute 'taoId'
91
-
92
- constructor: ->
93
- _instance = superClass.apply @, arguments
94
- @_created()
95
- return _instance
96
-
97
- connectedCallback: ->
98
- $ =>
99
- @connected = true
100
-
101
- unless @initialized
102
- @taoId = ++count
103
- @_init()
104
- @initialized = true
105
- @namespacedTrigger 'initialized'
106
-
107
- @_connected()
108
- @namespacedTrigger 'connected'
109
-
110
- disconnectedCallback: ->
111
- $ =>
112
- @connected = false
113
- @_disconnected()
114
- @namespacedTrigger 'disconnected'
115
-
116
- attributeChangedCallback: (name) ->
117
- return unless @connected
118
- @_attributeChanged name
119
-
120
- _created: ->
121
- # called when the element was created
122
-
123
- _init: ->
124
- # called when the element was connected to dom for the first time
125
-
126
- _connected: ->
127
- # called when the element was connected to dom
128
-
129
- _disconnected: ->
130
- # called when the element was disconnected from dom
131
-
132
- _beforeAttributeChanged: (name, val) ->
133
- @["_before#{_.upperFirst _.camelCase name}Changed"]?(val)
134
-
135
- _attributeChanged: (name) ->
136
- @["_#{_.camelCase name}Changed"]?()
137
-
138
- reflow: ->
139
- Tao.helpers.reflow @
140
- @
141
-
142
- beforeCache: ->
143
- # called before turbolinks cache pages
144
-
145
- findComponent: (selectors...) ->
146
- callback = selectors.pop() if _.isFunction(_.last(selectors))
147
- Tao.helpers.findComponent selectors, callback, @
148
-
149
- on: (name, args...) ->
150
- if name && name.indexOf('.') < 0
151
- name = "#{name}.#{@constructor._tag}-#{@taoId}"
152
- @jq.on name, args...
153
-
154
- off: (name = '', args...) ->
155
- if name.indexOf('.') < 0
156
- name = "#{name}.#{@constructor._tag}-#{@taoId}"
157
- @jq.off name, args...
158
-
159
- trigger: (args...) ->
160
- @jq.trigger(args...)
161
-
162
- triggerHandler: (args...) ->
163
- @jq.triggerHandler(args...)
164
-
165
- namespacedTrigger: (name, params) ->
166
- @trigger "tao:#{name}", params
167
- @trigger "#{@constructor._tag}:#{name}", params
168
-
169
- one: (args...) ->
170
- @jq.one args...
171
-
172
- components[superClassName] = ComponentClass
173
-
174
- Tao.TaoComponentBasedOn = window.TaoComponentBasedOn = TaoComponentBasedOn
175
- Tao.Component = window.TaoComponent = TaoComponentBasedOn 'HTMLElement'
@@ -1,34 +0,0 @@
1
-
2
- Tao.helpers =
3
-
4
- reflow: (el) ->
5
- $(el)[0].offsetHeight
6
-
7
- findComponent: (selectors, callback, scope = document) ->
8
- selectors = [selectors] unless _.isArray selectors
9
- components = _.flatten selectors.map (s) => $(scope).find(s).get()
10
-
11
- if components.length > 0 && _.isFunction callback
12
- Tao.helpers.componentReady components, -> callback(components...)
13
-
14
- if components.length > 1
15
- components
16
- else if components.length == 1
17
- components[0]
18
- else
19
- null
20
-
21
- componentReady: (components, callback) ->
22
- components = [components] unless _.isArray components
23
- promises = components.map (el) ->
24
- deferred = $.Deferred()
25
- if el.connected
26
- setTimeout -> deferred.resolve()
27
- else
28
- el.on 'tao:connected.taoReady', (e) ->
29
- return unless e.target == el
30
- el.off 'tao:connected.taoReady'
31
- deferred.resolve()
32
- deferred.promise()
33
-
34
- $.when(promises...).then -> callback()
@@ -1,14 +0,0 @@
1
- #= require polyfills
2
- #= require turbolinks
3
- #= require jquery3
4
- #= require jquery_ujs
5
- #= require lodash
6
-
7
- #= require_self
8
- #= require ./helpers
9
- #= require ./module
10
- #= require ./component
11
- #= require ./application
12
- #= require ./page
13
-
14
- window.Tao = {}
@@ -1,93 +0,0 @@
1
- class TaoModule
2
-
3
- id = 0
4
-
5
- @extend: (obj) ->
6
- obj = obj.call(@) if _.isFunction obj
7
- return unless obj and typeof obj == 'object'
8
-
9
- for key, val of obj when key not in ['included', 'extended']
10
- @[key] = val
11
-
12
- obj.extended?.call(@)
13
- @
14
-
15
- @include: (obj) ->
16
- obj = obj.call(@) if _.isFunction obj
17
- return unless obj and typeof obj == 'object'
18
-
19
- for key, val of obj when key not in ['included', 'extended']
20
- @::[key] = val
21
-
22
- obj.included?.call(@)
23
- @
24
-
25
- @get: (name, method) ->
26
- Object.defineProperty @prototype, name,
27
- get: method
28
- configurable: true
29
-
30
- @set: (name, method) ->
31
- Object.defineProperty @prototype, name,
32
- set: method
33
- configurable: true
34
-
35
- @property: (names..., options = {}) ->
36
- unless typeof options == 'object'
37
- names.push(options)
38
- options = {}
39
-
40
- names.forEach (name) =>
41
- @get name, ->
42
- unless _.isUndefined @_proterties[name]
43
- @_proterties[name]
44
- else if _.isFunction options.default
45
- options.default.call @
46
- else
47
- options.default
48
- @set name, (val) ->
49
- return if @_proterties[name] == val
50
- @_proterties[name] = val
51
- @["_#{name}Changed"]?()
52
-
53
- @_options: []
54
-
55
- @option: (names..., options = {}) ->
56
- unless typeof options == 'object'
57
- names.push(options)
58
- options = {}
59
-
60
- names.forEach (name) =>
61
- @_options.push(name) unless name in @_options
62
- @property name, options
63
-
64
- @aliasMethod: (newMethod, oldMethod) ->
65
- @::[newMethod] = ->
66
- @[oldMethod]?.apply(@, arguments)
67
-
68
- constructor: (options = {}) ->
69
- @id = ++id
70
- @_proterties = {}
71
-
72
- if _.isObject options
73
- for key, val of options
74
- @[key] = val if key in @constructor._options
75
-
76
- @_init()
77
-
78
- _init: ->
79
- # to be implemented
80
-
81
- on: (args...) ->
82
- $(@).on args...
83
-
84
- off: (args...) ->
85
- $(@).off args...
86
-
87
- trigger: (args...) ->
88
- $(@).triggerHandler(args...)
89
-
90
- one: (args...) ->
91
- $(@).one args...
92
-
93
- Tao.Module = window.TaoModule = TaoModule
@@ -1,9 +0,0 @@
1
- #= require ./component
2
-
3
- class TaoPage extends TaoComponent
4
-
5
- @attribute 'layout', default: 'default'
6
-
7
- beforeCache: ->
8
-
9
- Tao.Page = window.TaoPage = TaoPage
@@ -1,3 +0,0 @@
1
- .tao-page {
2
- display: block;
3
- }
@@ -1,18 +0,0 @@
1
- Description:
2
- Generate assets files for tao page.
3
-
4
- Example:
5
- `rails generate tao:assets employee index`
6
-
7
- Create files:
8
- app/assets/javascripts/employees/index_page.coffee
9
- app/assets/stylesheets/employees/index_page.scss
10
-
11
-
12
- `rails generate tao:assets home index --variants=default phone`
13
-
14
- Create files:
15
- app/assets/javascripts/default/employees/index_page.coffee
16
- app/assets/stylesheets/default/employees/index_page.scss
17
- app/assets/javascripts/phone/employees/index_page.coffee
18
- app/assets/stylesheets/phone/employees/index_page.scss
@@ -1,8 +0,0 @@
1
- module Tao
2
- module Generators
3
- class AssetsGenerator < ::Rails::Generators::NamedBase
4
- hook_for "coffee", in: :tao, type: :boolean, default: true
5
- hook_for "sass", in: :tao, type: :boolean, default: true
6
- end
7
- end
8
- end
@@ -1,9 +0,0 @@
1
- Description:
2
- Generate channel files for action cable.
3
-
4
- Example:
5
- `rails generate tao:channel chat speak`
6
-
7
- Create files:
8
- app/assets/javascripts/channels/chat.coffee
9
- app/channels/chat_channel.rb
@@ -1,17 +0,0 @@
1
- module Tao
2
- module Generators
3
- class ChannelGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- argument :actions, type: :array, default: [], banner: "method method"
7
-
8
- check_class_collision suffix: "Channel"
9
-
10
- def create_channel_files
11
- template "channel.coffee.erb", "app/assets/javascripts/channels/#{name.singularize}.coffee"
12
- template "channel.rb.erb", "app/channels/#{name.singularize}_channel.rb"
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,20 +0,0 @@
1
- app.<%= class_name.camelize(:lower) %>Channel = app.cable.subscriptions.create "<%= class_name %>Channel",
2
- connected: ->
3
- # Called when the subscription is ready for use on the server
4
- if app.currentPage
5
- currentPage.trigger 'channel-connected', ['<%= class_name.underscore %>']
6
-
7
- disconnected: ->
8
- # Called when the subscription has been terminated by the server
9
- if app.currentPage
10
- currentPage.trigger 'channel-disconnected', ['<%= class_name.underscore %>']
11
-
12
- received: (data) ->
13
- # Called when there's incoming data on the websocket for this channel
14
- if app.currentPage
15
- currentPage.trigger 'channel-received', ['<%= class_name.underscore %>', data]
16
- <% actions.each do |action| -%>
17
-
18
- <%= action %>: ->
19
- @perform '<%= action %>'
20
- <% end -%>
@@ -1,13 +0,0 @@
1
- class <%= class_name %>Channel < ApplicationCable::Channel
2
- def subscribed
3
- # stream_from "some_channel"
4
- end
5
-
6
- def unsubscribed
7
- # Any cleanup needed when channel is unsubscribed
8
- end
9
- <% actions.each do |action| -%>
10
- def <%= action %>
11
- end
12
- <% end -%>
13
- end
@@ -1,15 +0,0 @@
1
- Description:
2
- Generate coffee files for tao page.
3
-
4
- Example:
5
- `rails generate tao:coffee employee new`
6
-
7
- Create coffee file:
8
- app/assets/javascripts/employees/new.coffee
9
-
10
-
11
- `rails generate tao:coffee employee index --variants=default phone`
12
-
13
- Create coffee files:
14
- app/assets/javascripts/default/employees/index.coffee
15
- app/assets/javascripts/phone/employees/index.coffee
@@ -1,27 +0,0 @@
1
- module Tao
2
- module Generators
3
- class CoffeeGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- argument :actions, type: :array, default: %w(index new edit show), banner: "new edit"
7
-
8
- class_option :variants, type: :array, default: [], desc: "Generate assets for different variants"
9
-
10
- attr_reader :page_id
11
-
12
- def create_coffee_file
13
- actions.each do |action|
14
- @page_id = [class_path, file_name, action].flatten.join('-')
15
- if (variants = options[:variants]).any?
16
- variants.each do |variant|
17
- template "coffee.erb", File.join("app/assets/javascripts", variant, name.pluralize, "#{action}_page.coffee")
18
- end
19
- else
20
- template "coffee.erb", File.join('app/assets/javascripts', name.pluralize, "#{action}_page.coffee")
21
- end
22
- end
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,14 +0,0 @@
1
- class <%= page_id.underscore.camelize %>Page extends TaoPage
2
-
3
- @tag "<%= page_id %>-page"
4
-
5
- _init: ->
6
- # called when the page connected to dom for the first time
7
-
8
- _connected: ->
9
- # called every time the page connected to dom
10
-
11
- _disconnected: ->
12
- # called every time the page disconnected from dom
13
-
14
- TaoPage.register <%= page_id.underscore.camelize %>Page
@@ -1,5 +0,0 @@
1
- class <%= component_name.camelize %> extends TaoComponent
2
-
3
- @tag 'app-<%= component_name.dasherize %>'
4
-
5
- TaoComponent.register <%= component_name.camelize %>
@@ -1,3 +0,0 @@
1
- app-<%= component_name.dasherize %> {
2
-
3
- }
@@ -1,8 +0,0 @@
1
- Description:
2
- Generate controller files
3
-
4
- Example:
5
- `rails generate tao:controller home index`
6
-
7
- Create file:
8
- app/controllers/home_controller.rb
@@ -1,20 +0,0 @@
1
- module Tao
2
- module Generators
3
-
4
- class ControllerGenerator < Rails::Generators::NamedBase
5
- source_root File.expand_path('../templates', __FILE__)
6
-
7
- argument :actions, type: :array, default: %w(index new create edit update show destroy), banner: "action action"
8
-
9
- check_class_collision suffix: "Controller"
10
-
11
- attr_reader :resource
12
-
13
- def create_controller_file
14
- @resource = file_name.singularize
15
- template "controller.rb.erb", File.join('app/controllers', class_path, "#{file_name}_controller.rb")
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,57 +0,0 @@
1
- class <%= class_name %>Controller < ApplicationController
2
- <% if "new".in? actions %>
3
- def new
4
- build_<%= resource %>
5
- end
6
- <% end -%>
7
- <% if "create".in? actions %>
8
- def create
9
- build_<%= resource %>
10
- @<%= resource %>.save
11
- end
12
- <% end -%>
13
- <% if "edit".in? actions %>
14
- def edit
15
- load_<%= resource %>
16
- build_<%= resource %>
17
- end
18
- <% end -%>
19
- <% if "update".in? actions %>
20
- def update
21
- load_<%= resource %>
22
- build_<%= resource %>
23
- @<%= resource %>.save
24
- end
25
- <% end -%>
26
- <% if "show".in? actions %>
27
- def show
28
- load_<%= resource %>
29
- end
30
- <% end -%>
31
- <% if "destroy".in? actions %>
32
- def destroy
33
- load_<%= resource %>
34
- @<%= resource %>.destroy
35
- end
36
- <% end -%>
37
- <% unless actions.empty? %>
38
- private
39
- <% end -%>
40
- <% unless actions == %w(destroy) %>
41
- def build_<%= resource %>
42
- @<%= resource %> ||= <%= class_name %>.new
43
- @<%= resource %>.attributes = <%= resource %>_params
44
- end
45
- <% end -%>
46
- <% if (actions & %w(edit update show destroy)).any? %>
47
- def load_<%= resource %>
48
- @<%= resource %> = <%= class_name %>.find params[:id]
49
- end
50
- <% end -%>
51
- <% unless actions == %w(destroy) %>
52
- def <%= resource %>_params
53
- params.fetch(:<%= singular_table_name %>, {}).permit()
54
- end
55
- <% end -%>
56
-
57
- end
@@ -1,11 +0,0 @@
1
- Description:
2
- Generate locale files
3
-
4
- Example:
5
- `rails generate tao:locale namespace/resource zh-CN en`
6
-
7
- Create files:
8
- config/locales/models/namespace/resource/zh-CN.yml
9
- config/locales/models/namespace/resource/en.yml
10
- config/locales/views/namespace/resources/zh-CN.yml
11
- config/locales/views/namespace/resources/en.yml
@@ -1,34 +0,0 @@
1
- module Tao
2
- module Generators
3
- class LocaleGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- argument :locales, type: :array, default: [I18n.locale], banner: "locale locale"
7
-
8
- class_option :model, type: :boolean, default: true, desc: "Generate locale files for model"
9
- class_option :view, type: :boolean, default: true, desc: "Generate locale files for view"
10
-
11
- attr_reader :locale
12
-
13
- def copy_to_model
14
- return unless options[:model]
15
- locales.each do |locale|
16
- @locale = locale
17
- template "model.yml.erb", File.join('config/locales/models', name.pluralize, "#{locale}.yml")
18
- end
19
- end
20
-
21
- def copy_to_view
22
- return unless options[:view]
23
- file_content = (class_path + [plural_name]).reverse.inject(nil) do |content, path|
24
- { path => content }
25
- end
26
- locales.each do |locale|
27
- @locale = locale
28
- create_file File.join('config/locales/views', name.pluralize, "#{locale}.yml"), {locale => file_content}.to_yaml
29
- end
30
- end
31
-
32
- end
33
- end
34
- end
@@ -1,7 +0,0 @@
1
- <%= locale %>:
2
- activerecord:
3
- models:
4
- <%= template_namespace = class_path.map(&:pluralize).join('/') %>/<%= template_name = singular_name.singularize %>: <%= template_name.capitalize %>
5
- attributes:
6
- <%= template_namespace %>/<%= template_name %>:
7
- # attributes
@@ -1,15 +0,0 @@
1
- Description:
2
- Generate sass files for tao page.
3
-
4
- Example:
5
- `rails generate tao:sass employee new`
6
-
7
- Create coffee file:
8
- app/assets/stylesheets/employees/new.coffee
9
-
10
-
11
- `rails generate tao:sass employee index --variants=default phone`
12
-
13
- Create coffee files:
14
- app/assets/stylesheets/default/employees/index.coffee
15
- app/assets/stylesheets/phone/employees/index.coffee