tao_on_rails 0.6.2 → 0.6.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: f3c6267c2913b2dde1120969bb3d9aaf31fbd44a
4
- data.tar.gz: 348f07e5e6b7ae5bf850e2f1739cbe2c10939045
3
+ metadata.gz: 68741607aaee03755cb22bdc37f591a968ef990a
4
+ data.tar.gz: 11202a57a4788bb0bb3bf732930d34d6fa9d4600
5
5
  SHA512:
6
- metadata.gz: 2b2ca6b983f5edbbaa9485f758226393ad1a0381cf571ba7c822d57f586531a630f6420ff91edaefcbcbfafe642ecec8f15701fef4de36953bb6b1c8fbdb9b06
7
- data.tar.gz: 6fea03e197c664e99f21dc59dae336c69851c1b5eb33bb518b6671c440cf57e1dc578f6d0312ef5ef9a23b035433214025dcd3d509c5ccdd662f78667aec01dc
6
+ metadata.gz: 2e23efda6d1a2fbf658e5889d47b230f969d9009c01cf3441ffa95087e389e7f8ccc7208f7c2adf746409914f214fe5c1c66160a6c829842491b446a82f4fa00
7
+ data.tar.gz: 757f9688506a85930b7c36cc07ee7f55246810908f6742069079613eb66eafed3c179eda9f80c8167354d1cc9844366a16465088d61b3f7e88c743241af57e4a
data/README.md CHANGED
@@ -16,6 +16,7 @@ Several generators are available for you to quickly start your work:
16
16
  * tao:view
17
17
  * tao:controller
18
18
  * tao:locale
19
+ * tao:icons
19
20
  * tao:channel
20
21
  * tao:scaffold
21
22
 
@@ -68,4 +68,4 @@ class TaoApplication extends TaoModule
68
68
  @_initPage $page
69
69
  @trigger 'page-load', [@currentPage]
70
70
 
71
- window.TaoApplication = TaoApplication
71
+ Tao.Application = window.TaoApplication = TaoApplication
@@ -0,0 +1,101 @@
1
+ #= require ./module
2
+
3
+ parser = null
4
+
5
+ class TaoAttributeParser extends TaoModule
6
+
7
+ @defaultOptions =
8
+ type: 'string'
9
+
10
+ @getParser: ->
11
+ parser ||= new TaoAttributeParser()
12
+
13
+ @parse: (value, options = {}) ->
14
+ parser = @getParser()
15
+ options = _.extend {}, @defaultOptions, options
16
+ if parse = parser["_#{_.camelCase "parse_#{options.type}"}"]
17
+ parse.call parser, value, options
18
+ else
19
+ value
20
+
21
+ @stringify: (value, options = {}) ->
22
+ parser = @getParser()
23
+ options = _.extend {}, @defaultOptions, options
24
+ if stringify = parser["_#{_.camelCase "stringify_#{options.type}"}"]
25
+ stringify.call parser, value, options
26
+ else
27
+ value
28
+
29
+ _parseString: (value, options) ->
30
+ value || options.default || ''
31
+
32
+ _parseBoolean: (value, options) ->
33
+ if _.isNil value
34
+ options.default || false
35
+ else if value == 'true'
36
+ true
37
+ else if value == 'false'
38
+ false
39
+ else
40
+ !!value
41
+
42
+ @aliasMethod '_parseBool', '_parseBoolean'
43
+
44
+ _parseHash: (value, options) ->
45
+ if _.isString value
46
+ try
47
+ JSON.parse value
48
+ catch e
49
+ options.default || {}
50
+ else
51
+ options.default || {}
52
+
53
+ @aliasMethod '_parseObject', '_parseHash'
54
+
55
+ _parseArray: (value, options) ->
56
+ if _.isString value
57
+ try
58
+ JSON.parse value
59
+ catch e
60
+ options.default || []
61
+ else
62
+ options.default || []
63
+
64
+ _stringifyString: (value, options) ->
65
+ value.toString()
66
+
67
+ _stringifyBoolean: (value, options) ->
68
+ console.log @
69
+ unless _.isBoolean value
70
+ value = options.default || false
71
+
72
+ if value == true
73
+ 'true'
74
+ else if value == false
75
+ 'false'
76
+ else
77
+ null
78
+
79
+ @aliasMethod '_stringifyBool', '_stringifyBoolean'
80
+
81
+ _stringifyHash: (value, options) ->
82
+ unless _.isObject value
83
+ value = options.default || {}
84
+
85
+ try
86
+ JSON.stringify value
87
+ catch e
88
+ '{}'
89
+
90
+ @aliasMethod '_stringifyObject', '_stringifyHash'
91
+
92
+ _stringifyArray: (value, options) ->
93
+ unless _.isObject value
94
+ value = options.default || []
95
+
96
+ try
97
+ JSON.stringify value
98
+ catch e
99
+ '[]'
100
+
101
+ Tao.AttributeParser = window.TaoAttributeParser = TaoAttributeParser
@@ -1,5 +1,6 @@
1
1
  #= require lodash
2
2
  #= require polyfills/polyfills
3
+ #= require ./attribute_parser
3
4
 
4
5
  components = {}
5
6
 
@@ -63,23 +64,21 @@ TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
63
64
 
64
65
  names.forEach (name) =>
65
66
  attrName = _.kebabCase(name)
67
+
66
68
  @get name, ->
67
- if @hasAttribute attrName
68
- val = @getAttribute(attrName)
69
- if val == 'false' then false else (val || true)
70
- else if options.default
71
- options.default
69
+ val = if @hasAttribute attrName
70
+ @getAttribute(attrName)
72
71
  else
73
- false
72
+ null
73
+ TaoAttributeParser.parse val, options
74
+
74
75
  @set name, (val) ->
75
- if val == true
76
- @setAttribute attrName, ''
77
- else if val != false
76
+ val = TaoAttributeParser.stringify val, options
77
+ if _.isString val
78
78
  @setAttribute attrName, val
79
- else if options.default == true
80
- @setAttribute attrName, 'false'
81
79
  else
82
80
  @removeAttribute attrName
81
+
83
82
  @observedAttributes.push(attrName) if options.observe
84
83
 
85
84
  @tag: '' # to be set by child class
@@ -149,5 +148,5 @@ TaoComponentBasedOn = (superClassName = 'HTMLElement') ->
149
148
 
150
149
  components[superClassName] = ComponentClass
151
150
 
152
- window.TaoComponentBasedOn = TaoComponentBasedOn
153
- window.TaoComponent = TaoComponentBasedOn 'HTMLElement'
151
+ Tao.TaoComponentBasedOn = window.TaoComponentBasedOn = TaoComponentBasedOn
152
+ Tao.Component = window.TaoComponent = TaoComponentBasedOn 'HTMLElement'
@@ -1,2 +1,2 @@
1
- # generate this file by exec command in project:
2
- # rake tao:generate_icons
1
+ # generate this file by generator:
2
+ # rails g tao:icons
@@ -22,32 +22,41 @@ class TaoModule
22
22
  obj.included?.call(@)
23
23
  @
24
24
 
25
- @get: (attributeName, getMethod) ->
26
- Object.defineProperty @prototype, attributeName,
27
- get: getMethod
25
+ @get: (name, method) ->
26
+ Object.defineProperty @prototype, name,
27
+ get: method
28
28
  configurable: true
29
29
 
30
- @set: (attributeName, setMethod) ->
31
- Object.defineProperty @prototype, attributeName,
32
- set: setMethod
30
+ @set: (name, method) ->
31
+ Object.defineProperty @prototype, name,
32
+ set: method
33
33
  configurable: true
34
34
 
35
- @attribute: (names..., options = {}) ->
35
+ @property: (names..., options = {}) ->
36
36
  unless typeof options == 'object'
37
37
  names.push(options)
38
38
  options = {}
39
39
 
40
40
  names.forEach (name) =>
41
41
  @get name, ->
42
- @_attributes[name] ? options.default
42
+ unless _.isUndefined @_proterties[name]
43
+ @_proterties[name]
44
+ else if _.isFunction options.default
45
+ options.default.call @
46
+ else
47
+ options.default
43
48
  @set name, (val) ->
44
- return if @_attributes[name] == val
45
- @_attributes[name] = val
49
+ return if @_proterties[name] == val
50
+ @_proterties[name] = val
46
51
  @["_#{name}Changed"]?()
47
52
 
53
+ @aliasMethod: (newMethod, oldMethod) ->
54
+ @::[newMethod] = ->
55
+ @[oldMethod]?.apply(@, arguments)
56
+
48
57
  constructor: (options = {}) ->
49
58
  @id = ++id
50
- @_attributes = {}
59
+ @_proterties = {}
51
60
 
52
61
  if typeof options == 'object'
53
62
  @[key] = val for key, val of options
@@ -69,4 +78,4 @@ class TaoModule
69
78
  one: (args...) ->
70
79
  $(@).one args...
71
80
 
72
- window.TaoModule = TaoModule
81
+ Tao.Module = window.TaoModule = TaoModule
@@ -9,4 +9,4 @@ class TaoPage extends TaoComponent
9
9
  el.beforeCache?()
10
10
  null
11
11
 
12
- window.TaoPage = TaoPage
12
+ Tao.Page = window.TaoPage = TaoPage
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate coffee file containing all svg icons.
3
+
4
+ Example:
5
+ `rails generate tao:icons`
6
+
7
+ Create coffee file:
8
+ lib/assets/javascripts/tao/icons.coffee
@@ -0,0 +1,44 @@
1
+ module Tao
2
+ module Generators
3
+ class IconsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ class_option :svg_path, type: :string, default: 'app/assets/icons', desc: "Directory path containing svg source files."
7
+
8
+ attr_reader :icons_html
9
+
10
+ def create_icons_file
11
+ @icons_html = svg_files.map {|file| " #{symbol(file)}\n"}.join
12
+ template 'icons.coffee.erb', 'lib/assets/javascripts/tao/icons.coffee'
13
+ end
14
+
15
+ private
16
+
17
+ def svg_files
18
+ Dir.glob(File.expand_path(File.join(options[:svg_path], '*.svg'), destination_root)).uniq
19
+ end
20
+
21
+ def symbol(path)
22
+ name = File.basename(path, ".*").underscore().dasherize()
23
+ content = File.read(path)
24
+ content.gsub(/<?.+\?>/,'')
25
+ .gsub(/<!.+?>/,'')
26
+ .gsub(/<title>.*<\/title>/, '')
27
+ .gsub(/<desc>.*<\/desc>/, '')
28
+ .gsub(/id=/,'class=')
29
+ .gsub(/<svg.+?>/, %Q{<svg id="icon-#{name}" #{dimensions(content)}>})
30
+ .gsub(/svg/,'symbol')
31
+ .gsub(/\sfill=".+?"/,'')
32
+ .gsub(/\n/, '') # Remove endlines
33
+ .gsub(/\s{2,}/, ' ') # Remove whitespace
34
+ .gsub(/>\s+</, '><') # Remove whitespace between tags
35
+ end
36
+
37
+ def dimensions(content)
38
+ dimension = content.scan(/<svg.+(viewBox=["'](.+?)["'])/).flatten
39
+ %Q{#{dimension.first} width="100%" height="100%"}
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ Tao.iconsHtml = '''
2
+ <svg id="tao-icons" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none">
3
+ <%= icons_html %>
4
+ </svg>
5
+ '''
@@ -1,3 +1,3 @@
1
1
  module TaoOnRails
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
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.6.2
4
+ version: 0.6.3
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-01-19 00:00:00.000000000 Z
12
+ date: 2017-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: turbolinks
@@ -73,6 +73,20 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 5.0.1
76
+ - !ruby/object:Gem::Dependency
77
+ name: sqlite3
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: blade
78
92
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +131,7 @@ files:
117
131
  - lib/assets/javascripts/i18n.js
118
132
  - lib/assets/javascripts/tao.coffee
119
133
  - lib/assets/javascripts/tao/application.coffee
134
+ - lib/assets/javascripts/tao/attribute_parser.coffee
120
135
  - lib/assets/javascripts/tao/component.coffee
121
136
  - lib/assets/javascripts/tao/helpers.coffee
122
137
  - lib/assets/javascripts/tao/icons.coffee
@@ -136,6 +151,9 @@ files:
136
151
  - lib/generators/tao/controller/USAGE
137
152
  - lib/generators/tao/controller/controller_generator.rb
138
153
  - lib/generators/tao/controller/templates/controller.rb.erb
154
+ - lib/generators/tao/icons/USAGE
155
+ - lib/generators/tao/icons/icons_generator.rb
156
+ - lib/generators/tao/icons/templates/icons.coffee.erb
139
157
  - lib/generators/tao/locale/USAGE
140
158
  - lib/generators/tao/locale/locale_generator.rb
141
159
  - lib/generators/tao/locale/templates/model.yml.erb
@@ -156,7 +174,6 @@ files:
156
174
  - lib/tao_on_rails.rb
157
175
  - lib/tao_on_rails/engine.rb
158
176
  - lib/tao_on_rails/version.rb
159
- - lib/tasks/icons.rake
160
177
  - lib/templates/app/app_template.rb
161
178
  - lib/templates/app/templates/app/assets/javascripts/application.coffee
162
179
  - lib/templates/app/templates/app/assets/javascripts/home/index_page.coffee
data/lib/tasks/icons.rake DELETED
@@ -1,48 +0,0 @@
1
- namespace :tao do
2
-
3
- desc 'generate svg icons.'
4
- task :icons => :environment do
5
- dir_name = "#{Rails.root}/vendor/assets/javascripts/tao"
6
- Dir.mkdir(dir_name) unless File.exists?(dir_name)
7
-
8
- File.open "#{dir_name}/icons.coffee", 'w' do |f|
9
- f.puts %{Tao.iconsHtml = '''#{svg_html}'''}
10
- end
11
- end
12
-
13
- private
14
-
15
- def svg_html
16
- %{<svg id="tao-icons" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none">\n#{symbols}</svg>}
17
- end
18
-
19
- def svg_files
20
- @svg_files ||= Dir.glob(File.expand_path("#{::Rails.root}/app/assets/icons/*.svg")).uniq
21
- end
22
-
23
- def symbols
24
- svg_files.map {|file| " #{symbol(file)}\n"}.join
25
- end
26
-
27
- def symbol(path)
28
- name = File.basename(path, ".*").underscore().dasherize()
29
- content = File.read(path)
30
- content.gsub(/<?.+\?>/,'')
31
- .gsub(/<!.+?>/,'')
32
- .gsub(/<title>.*<\/title>/, '')
33
- .gsub(/<desc>.*<\/desc>/, '')
34
- .gsub(/id=/,'class=')
35
- .gsub(/<svg.+?>/, %Q{<svg id="icon-#{name}" #{dimensions(content)}>})
36
- .gsub(/svg/,'symbol')
37
- .gsub(/\sfill=".+?"/,'')
38
- .gsub(/\n/, '') # Remove endlines
39
- .gsub(/\s{2,}/, ' ') # Remove whitespace
40
- .gsub(/>\s+</, '><') # Remove whitespace between tags
41
- end
42
-
43
- def dimensions(content)
44
- dimension = content.scan(/<svg.+(viewBox=["'](.+?)["'])/).flatten
45
- %Q{#{dimension.first} width="100%" height="100%"}
46
- end
47
-
48
- end