opalla 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +394 -14
- data/lib/opalla.rb +11 -4
- data/lib/opalla/component_helper.rb +28 -0
- data/lib/opalla/controller_add_on.rb +11 -0
- data/lib/opalla/engine.rb +27 -0
- data/lib/opalla/middleware.rb +20 -0
- data/lib/opalla/util.rb +63 -0
- data/lib/opalla/version.rb +1 -1
- data/lib/rails/generators/opalla/assets_generator.rb +23 -0
- data/lib/rails/generators/opalla/collection_generator.rb +19 -0
- data/lib/rails/generators/opalla/component_generator.rb +27 -0
- data/lib/rails/generators/opalla/install_generator.rb +62 -0
- data/lib/rails/generators/opalla/model_generator.rb +19 -0
- data/opal/collection.rb +71 -0
- data/opal/component.rb +136 -0
- data/opal/controller.rb +60 -0
- data/opal/diffDOM.js +1371 -0
- data/opal/diff_dom.rb +26 -0
- data/opal/element.rb +17 -0
- data/opal/hex_random.rb +12 -0
- data/opal/model.rb +50 -0
- data/opal/opalla.rb +21 -0
- data/opal/router.rb +66 -0
- data/opal/sha1.js +366 -0
- data/opal/view_helper.rb +168 -0
- data/opalla.gemspec +8 -0
- data/opalla.gif +0 -0
- metadata +109 -2
data/opal/view_helper.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
module Opalla
|
2
|
+
module TagHelper
|
3
|
+
BOOLEAN_ATTRIBUTES = %w(allowfullscreen async autofocus autoplay checked
|
4
|
+
compact controls declare default defaultchecked
|
5
|
+
defaultmuted defaultselected defer disabled
|
6
|
+
enabled formnovalidate hidden indeterminate inert
|
7
|
+
ismap itemscope loop multiple muted nohref
|
8
|
+
noresize noshade novalidate nowrap open
|
9
|
+
pauseonexit readonly required reversed scoped
|
10
|
+
seamless selected sortable truespeed typemustmatch
|
11
|
+
visible).to_set
|
12
|
+
|
13
|
+
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))
|
14
|
+
|
15
|
+
TAG_PREFIXES = ["aria", "data", :aria, :data].to_set
|
16
|
+
|
17
|
+
PRE_CONTENT_STRINGS = Hash.new { "" }
|
18
|
+
PRE_CONTENT_STRINGS[:textarea] = "\n"
|
19
|
+
PRE_CONTENT_STRINGS["textarea"] = "\n"
|
20
|
+
|
21
|
+
class TagBuilder #:nodoc:
|
22
|
+
VOID_ELEMENTS = %i(area base br col embed hr img input keygen link meta param source track wbr).to_set
|
23
|
+
|
24
|
+
def initialize(view_context)
|
25
|
+
@view_context = view_context
|
26
|
+
end
|
27
|
+
|
28
|
+
def tag_string(name, content = nil, escape_attributes: true, **options, &block)
|
29
|
+
content = @view_context.capture(self, &block) if block_given?
|
30
|
+
if VOID_ELEMENTS.include?(name) && content.nil?
|
31
|
+
"<#{name.to_s.dasherize}#{tag_options(options, escape_attributes)}>"
|
32
|
+
else
|
33
|
+
content_tag_string(name.to_s.dasherize, content || "", options, escape_attributes)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def content_tag_string(name, content, options, escape = true)
|
38
|
+
tag_options = tag_options(options, escape) if options
|
39
|
+
"<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name]}#{content}</#{name}>"
|
40
|
+
end
|
41
|
+
|
42
|
+
def tag_options(options, escape = true)
|
43
|
+
return if options.blank?
|
44
|
+
output = "".dup
|
45
|
+
sep = " "
|
46
|
+
options.each_pair do |key, value|
|
47
|
+
if TAG_PREFIXES.include?(key) && value.is_a?(Hash)
|
48
|
+
value.each_pair do |k, v|
|
49
|
+
next if v.nil?
|
50
|
+
output += sep
|
51
|
+
output += prefix_tag_option(key, k, v, escape)
|
52
|
+
end
|
53
|
+
elsif BOOLEAN_ATTRIBUTES.include?(key)
|
54
|
+
if value
|
55
|
+
output += sep
|
56
|
+
output += boolean_tag_option(key)
|
57
|
+
end
|
58
|
+
elsif !value.nil?
|
59
|
+
output += sep
|
60
|
+
output += tag_option(key, value, escape)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
output unless output.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def boolean_tag_option(key)
|
67
|
+
%(#{key}="#{key}")
|
68
|
+
end
|
69
|
+
|
70
|
+
def tag_option(key, value, escape)
|
71
|
+
if value.is_a?(Array)
|
72
|
+
value = value.join(" ".freeze)
|
73
|
+
else
|
74
|
+
value = value.to_s
|
75
|
+
end
|
76
|
+
%(#{key}="#{value.gsub('"'.freeze, '"'.freeze)}")
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def prefix_tag_option(prefix, key, value, escape)
|
81
|
+
key = "#{prefix}-#{key.to_s.dasherize}"
|
82
|
+
unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Numeric)
|
83
|
+
value = value.to_json
|
84
|
+
end
|
85
|
+
tag_option(key, value, escape)
|
86
|
+
end
|
87
|
+
|
88
|
+
def respond_to_missing?(*args)
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
def method_missing(called, *args, &block)
|
93
|
+
tag_string(called, *args, &block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def tag(name = nil, options = nil, open = false, escape = true)
|
98
|
+
if name.nil?
|
99
|
+
tag_builder
|
100
|
+
else
|
101
|
+
"<#{name}#{tag_builder.tag_options(options, escape) if options}#{open ? ">" : " />"}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
106
|
+
if block_given?
|
107
|
+
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
108
|
+
tag_builder.content_tag_string(name, capture(&block), options, escape)
|
109
|
+
else
|
110
|
+
tag_builder.content_tag_string(name, content_or_options_with_block, options, escape)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def cdata_section(content)
|
115
|
+
splitted = content.to_s.gsub(/\]\]\>/, "]]]]><![CDATA[>")
|
116
|
+
"<![CDATA[#{splitted}]]>"
|
117
|
+
end
|
118
|
+
|
119
|
+
def escape_once(html)
|
120
|
+
ERB::Util.html_escape_once(html)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def tag_builder
|
125
|
+
@tag_builder ||= TagBuilder.new(self)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
module ViewHelper
|
130
|
+
def link_to(name = nil, options = nil, html_options = nil, &block)
|
131
|
+
html_options, options, name = options, name, block if block_given?
|
132
|
+
options ||= {}
|
133
|
+
|
134
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
135
|
+
|
136
|
+
url = options
|
137
|
+
html_options["href".freeze] ||= url
|
138
|
+
|
139
|
+
content_tag("a".freeze, name || url, html_options, &block)
|
140
|
+
end
|
141
|
+
|
142
|
+
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
143
|
+
if block_given?
|
144
|
+
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
145
|
+
tag_builder.content_tag_string(name, capture(&block), options, escape)
|
146
|
+
else
|
147
|
+
tag_builder.content_tag_string(name, content_or_options_with_block, options, escape)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
protected
|
152
|
+
|
153
|
+
def tag_builder
|
154
|
+
@tag_builder ||= Opalla::TagHelper::TagBuilder.new
|
155
|
+
end
|
156
|
+
|
157
|
+
def convert_options_to_data_attributes(options, html_options)
|
158
|
+
if html_options
|
159
|
+
|
160
|
+
method = html_options.delete('method')
|
161
|
+
|
162
|
+
add_method_to_attributes!(html_options, method) if method
|
163
|
+
|
164
|
+
html_options
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/opalla.gemspec
CHANGED
@@ -31,4 +31,12 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.14"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
|
35
|
+
spec.add_dependency 'activesupport'
|
36
|
+
spec.add_dependency 'opal'
|
37
|
+
spec.add_dependency 'opal-jquery'
|
38
|
+
spec.add_dependency 'opal-browser'
|
39
|
+
spec.add_dependency 'opal-activesupport'
|
40
|
+
spec.add_dependency 'opal-rails', '0.9.3'
|
41
|
+
|
34
42
|
end
|
data/opalla.gif
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opalla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Maciel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,90 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: opal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: opal-jquery
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: opal-browser
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: opal-activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: opal-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.3
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.3
|
41
125
|
description:
|
42
126
|
email:
|
43
127
|
- pedrozath@gmail.com
|
@@ -54,8 +138,31 @@ files:
|
|
54
138
|
- bin/console
|
55
139
|
- bin/setup
|
56
140
|
- lib/opalla.rb
|
141
|
+
- lib/opalla/component_helper.rb
|
142
|
+
- lib/opalla/controller_add_on.rb
|
143
|
+
- lib/opalla/engine.rb
|
144
|
+
- lib/opalla/middleware.rb
|
145
|
+
- lib/opalla/util.rb
|
57
146
|
- lib/opalla/version.rb
|
147
|
+
- lib/rails/generators/opalla/assets_generator.rb
|
148
|
+
- lib/rails/generators/opalla/collection_generator.rb
|
149
|
+
- lib/rails/generators/opalla/component_generator.rb
|
150
|
+
- lib/rails/generators/opalla/install_generator.rb
|
151
|
+
- lib/rails/generators/opalla/model_generator.rb
|
152
|
+
- opal/collection.rb
|
153
|
+
- opal/component.rb
|
154
|
+
- opal/controller.rb
|
155
|
+
- opal/diffDOM.js
|
156
|
+
- opal/diff_dom.rb
|
157
|
+
- opal/element.rb
|
158
|
+
- opal/hex_random.rb
|
159
|
+
- opal/model.rb
|
160
|
+
- opal/opalla.rb
|
161
|
+
- opal/router.rb
|
162
|
+
- opal/sha1.js
|
163
|
+
- opal/view_helper.rb
|
58
164
|
- opalla.gemspec
|
165
|
+
- opalla.gif
|
59
166
|
homepage: http://github.com/pedrozath/opalla
|
60
167
|
licenses:
|
61
168
|
- MIT
|