roda-component 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -29
- data/lib/roda/component/version.rb +1 -1
- data/lib/roda/plugins/component.rb +25 -26
- data/test/dummy/app.rb +3 -3
- data/test/dummy/components/layout.rb +1 -1
- data/test/dummy/components/login.rb +3 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0d11690e0fcadcb8e039e0da837a1e66d87f128
|
4
|
+
data.tar.gz: 383600a90a2d5ba621a5ad2208923a056e5a7416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbd1b842323e8bd39b3f822e80cd1c7e537bb7c6e4df5f729fe3df69793867d17d30dfcb22e4776150cbc6339a9785305a6a9459ca2e06583043a2a3cb0bb6d
|
7
|
+
data.tar.gz: 8d37da4c0faf072c3cfa0553404f5f7ad1b01a1913ba9f6e5df4f264a11cb97ff29859968e60f324851f4e1ec900eb90ea0649005620f1d21e7de4277258cb79
|
data/README.md
CHANGED
@@ -1,31 +1,6 @@
|
|
1
1
|
# Roda::Component
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'roda-component'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install roda-component
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
|
-
|
25
|
-
## Contributing
|
26
|
-
|
27
|
-
1. Fork it ( https://github.com/[my-github-username]/roda-component/fork )
|
28
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create a new Pull Request
|
3
|
+
## todo
|
4
|
+
- create a simple store object for each component
|
5
|
+
- have a comp_id class method where you can put logic in for generating unique id
|
6
|
+
this is mainly used to the store
|
@@ -95,7 +95,13 @@ class Roda
|
|
95
95
|
end
|
96
96
|
EOF
|
97
97
|
|
98
|
-
loaded_component_js << ("<script
|
98
|
+
loaded_component_js << ("<script>#{Opal.compile(js)}</script>")
|
99
|
+
|
100
|
+
file_path = comp.class.instance_methods(false).map { |m|
|
101
|
+
comp.class.instance_method(m).source_location.first
|
102
|
+
}.uniq.first.gsub("#{Dir.pwd}/#{component_opts[:path]}", '').gsub(/\.rb\Z/, '.js')
|
103
|
+
|
104
|
+
loaded_component_js << "<script type=\"text/javascript\" src=\"/#{component_opts[:assets_route]}#{file_path}\"></script>"
|
99
105
|
end
|
100
106
|
|
101
107
|
def component name, options = {}, &block
|
@@ -138,7 +144,7 @@ class Roda
|
|
138
144
|
alias :roda_component :component
|
139
145
|
|
140
146
|
def component_js
|
141
|
-
loaded_component_js.join('
|
147
|
+
loaded_component_js.join(' ').to_s
|
142
148
|
end
|
143
149
|
end
|
144
150
|
|
@@ -175,33 +181,26 @@ class Roda
|
|
175
181
|
|
176
182
|
module RequestMethods
|
177
183
|
def components
|
178
|
-
|
179
|
-
#
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
# Append the gems path
|
184
|
-
s.append_path Dir.pwd
|
185
|
-
s.append_path Gem::Specification.find_by_name("roda-component").gem_dir + '/lib'
|
186
|
-
# s.append_path Gem::Specification.find_by_name("scrivener-cj").gem_dir + '/lib'
|
187
|
-
# Append the path to the components folder
|
188
|
-
s.append_path scope.component_opts[:path]
|
189
|
-
|
190
|
-
s.main = 'application'
|
191
|
-
end
|
184
|
+
opal = Opal::Server.new do |s|
|
185
|
+
# Append the gems path
|
186
|
+
s.debug = true
|
187
|
+
s.source_map = true
|
188
|
+
s.append_path Gem::Specification.find_by_name("roda-component").gem_dir + '/lib'
|
192
189
|
|
193
|
-
|
190
|
+
# Append the path to the components folder
|
191
|
+
s.append_path scope.component_opts[:path]
|
194
192
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
end
|
201
|
-
# Set the header to javascript
|
202
|
-
response.headers["Content-Type"] = 'application/javascript; charset=UTF-8'
|
193
|
+
s.main = 'roda/component'
|
194
|
+
end
|
195
|
+
|
196
|
+
on self.class.component_assets_route_regex do |component, action|
|
197
|
+
path = scope.request.env['REQUEST_PATH']
|
203
198
|
|
204
|
-
js
|
199
|
+
if path[/\.js\Z/]
|
200
|
+
run opal.sprockets
|
201
|
+
else
|
202
|
+
run Opal::SourceMapServer.new(opal.sprockets, path)
|
203
|
+
end
|
205
204
|
end
|
206
205
|
|
207
206
|
on self.class.component_route_regex do |comp, type, action|
|
data/test/dummy/app.rb
CHANGED
@@ -41,7 +41,7 @@ class TestApp < Roda
|
|
41
41
|
secret: "na"
|
42
42
|
|
43
43
|
plugin :csrf, header: 'X-CSRF-TOKEN', skip: ['POST:/faye']
|
44
|
-
plugin :component, { path:
|
44
|
+
plugin :component, { path: 'components', token: '687^*&SAD876asd87as6d*&8asd' }
|
45
45
|
plugin :assets, {
|
46
46
|
path: "#{path}/../public/chat",
|
47
47
|
css_dir: '',
|
@@ -80,8 +80,8 @@ class TestApp < Roda
|
|
80
80
|
|
81
81
|
r.root { component(:chat, js: true) }
|
82
82
|
|
83
|
-
r.on('login')
|
84
|
-
r.on('logout') { component(:login, call: :logout
|
83
|
+
r.on('login') { component(:login, js: true) }
|
84
|
+
r.on('logout') { component(:login, call: :logout) }
|
85
85
|
|
86
86
|
r.on 'session/:key/:value' do |key, value|
|
87
87
|
session[key] = value
|
@@ -8,7 +8,7 @@ class LayoutComp < Roda::Component
|
|
8
8
|
dom.at_css('head').add_child assets(:css)
|
9
9
|
dom.at_css('html').add_child assets(:js)
|
10
10
|
dom.at_css('html').add_child <<-EOF
|
11
|
-
<script type="text/javascript" src="/assets/components"></script>
|
11
|
+
<script type="text/javascript" src="/assets/components/roda/component.js"></script>
|
12
12
|
<script type="text/javascript" src="/faye/client.js"></script>
|
13
13
|
EOF
|
14
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'forms/login'
|
2
|
+
|
1
3
|
class LoginComponent < Roda::Component
|
2
4
|
comp_name :login
|
3
5
|
comp_html "../public/chat/login.html"
|
@@ -17,7 +19,7 @@ class LoginComponent < Roda::Component
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def logout
|
20
|
-
|
22
|
+
super(Models::User)
|
21
23
|
request.redirect 'login'
|
22
24
|
end
|
23
25
|
|
@@ -97,11 +99,6 @@ class LoginComponent < Roda::Component
|
|
97
99
|
|
98
100
|
protected
|
99
101
|
|
100
|
-
def logout
|
101
|
-
logout(Models::User)
|
102
|
-
request.redirect 'login'
|
103
|
-
end
|
104
|
-
|
105
102
|
def display_errors errors
|
106
103
|
errors.each do |key, error|
|
107
104
|
error = error.first
|