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 +4 -4
- data/README.md +1 -0
- data/lib/assets/javascripts/tao/application.coffee +1 -1
- data/lib/assets/javascripts/tao/attribute_parser.coffee +101 -0
- data/lib/assets/javascripts/tao/component.coffee +12 -13
- data/lib/assets/javascripts/tao/icons.coffee +2 -2
- data/lib/assets/javascripts/tao/module.coffee +21 -12
- data/lib/assets/javascripts/tao/page.coffee +1 -1
- data/lib/generators/tao/icons/USAGE +8 -0
- data/lib/generators/tao/icons/icons_generator.rb +44 -0
- data/lib/generators/tao/icons/templates/icons.coffee.erb +5 -0
- data/lib/tao_on_rails/version.rb +1 -1
- metadata +20 -3
- data/lib/tasks/icons.rake +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68741607aaee03755cb22bdc37f591a968ef990a
|
4
|
+
data.tar.gz: 11202a57a4788bb0bb3bf732930d34d6fa9d4600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e23efda6d1a2fbf658e5889d47b230f969d9009c01cf3441ffa95087e389e7f8ccc7208f7c2adf746409914f214fe5c1c66160a6c829842491b446a82f4fa00
|
7
|
+
data.tar.gz: 757f9688506a85930b7c36cc07ee7f55246810908f6742069079613eb66eafed3c179eda9f80c8167354d1cc9844366a16465088d61b3f7e88c743241af57e4a
|
data/README.md
CHANGED
@@ -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
|
-
|
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
|
-
|
72
|
+
null
|
73
|
+
TaoAttributeParser.parse val, options
|
74
|
+
|
74
75
|
@set name, (val) ->
|
75
|
-
|
76
|
-
|
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
|
2
|
-
#
|
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: (
|
26
|
-
Object.defineProperty @prototype,
|
27
|
-
get:
|
25
|
+
@get: (name, method) ->
|
26
|
+
Object.defineProperty @prototype, name,
|
27
|
+
get: method
|
28
28
|
configurable: true
|
29
29
|
|
30
|
-
@set: (
|
31
|
-
Object.defineProperty @prototype,
|
32
|
-
set:
|
30
|
+
@set: (name, method) ->
|
31
|
+
Object.defineProperty @prototype, name,
|
32
|
+
set: method
|
33
33
|
configurable: true
|
34
34
|
|
35
|
-
@
|
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
|
-
@
|
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 @
|
45
|
-
@
|
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
|
-
@
|
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
|
@@ -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
|
data/lib/tao_on_rails/version.rb
CHANGED
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.
|
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-
|
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
|