rails_com 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +11 -3
- data/app/assets/javascripts/rails_com/application.js +1 -1
- data/app/assets/javascripts/rails_com/common.js +32 -0
- data/app/assets/javascripts/rails_com/fetch_xhr_script.js +53 -0
- data/app/assets/javascripts/rails_com/footer.js +3 -0
- data/app/assets/stylesheets/rails_com/application.css +0 -1
- data/app/controllers/common_controller.rb +18 -0
- data/app/controllers/concerns/the_common_api.rb +15 -3
- data/app/helpers/rails_com/active_helper.rb +17 -6
- data/app/helpers/rails_com_helper.rb +6 -3
- data/app/models/state_machine.rb +5 -4
- data/app/views/shared/_alert.html.erb +1 -5
- data/app/views/shared/_error_messages.html.erb +1 -7
- data/app/views/shared/_locales.html.erb +8 -0
- data/config/initializers/time_format.rb +1 -0
- data/config/locales/en.yml +8 -6
- data/config/routes.rb +7 -0
- data/lib/assets/javascripts/semantic.js +11 -0
- data/lib/mina/puma.rb +63 -0
- data/lib/mina/sidekiq.rb +65 -0
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot +0 -0
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf +0 -0
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg +946 -2670
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf +0 -0
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff +0 -0
- data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2 +0 -0
- data/lib/nondigest_assets/{images → fonts}/themes/default/assets/images/flags.png +0 -0
- data/lib/rails_com/controller_helper.rb +26 -1
- data/lib/rails_com/controllers.rb +8 -0
- data/lib/rails_com/core_ext/nil.rb +1 -1
- data/lib/rails_com/helpers/uid_helper.rb +24 -4
- data/lib/rails_com/rails_ext/scaffold_generator.rb +14 -0
- data/lib/rails_com/rails_ext/template_renderer.rb +22 -0
- data/lib/rails_com/routes.rb +12 -8
- data/lib/rails_com/sprockets/non_digest_assets.rb +0 -18
- data/lib/rails_com/version.rb +1 -1
- data/lib/rails_com.rb +11 -2
- data/lib/templates/erb/scaffold/_form.html.erb.tt +12 -0
- data/lib/templates/erb/scaffold/_search_form.html.erb.tt +7 -0
- data/lib/templates/erb/scaffold/edit.html.erb.tt +14 -0
- data/lib/templates/erb/scaffold/index.html.erb.tt +43 -0
- data/lib/templates/erb/scaffold/new.html.erb.tt +13 -0
- data/lib/templates/erb/scaffold/show.html.erb.tt +7 -0
- data/lib/templates/rails/scaffold_controller/controller.rb.tt +53 -0
- metadata +25 -16
- data/lib/assets/stylesheets/semantic.css +0 -19466
- data/lib/rails_com/helpers/qiniu_helper.rb +0 -84
- data/lib/rails_com/sprockets/qiniu_exporter.rb +0 -21
- data/lib/rails_com/sprockets.rb +0 -15
- data/lib/templates/erb/scaffold/_form.html.erb +0 -19
- data/lib/templates/erb/scaffold/edit.html.erb +0 -2
- data/lib/templates/erb/scaffold/index.html.erb +0 -36
- data/lib/templates/erb/scaffold/new.html.erb +0 -1
- data/lib/templates/erb/scaffold/show.html.erb +0 -13
- data/lib/templates/rails/scaffold_controller/controller.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91a9e381fa905dd733cdabed0016d6f6826b468e3d9a2d1af8eece1323d88d81
|
4
|
+
data.tar.gz: 95625b665362ccfea08fb4f9317a521e741adc0f765d0bef2996477aef0cc34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce5ae23bc46a4f2d667db8d8b21ee86b4fa8670a322074857d1cee11b0a6afd7c3e8c8cce0325cc15a6b65742c25dec7b486a48bb964e971df62f9d3b21734c
|
7
|
+
data.tar.gz: a6f1f3e942c26a68ad460f387146fe58304895fa8c46ac76c9f9053fcbf270ca4cd7288bb0cb5a6d4839275099e18ad1282fe517cfea796e34f52e508cb257c9
|
data/README.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# RailsCom
|
2
2
|
Short description and motivation.
|
3
3
|
|
4
|
-
## Usage
|
5
|
-
How to use my plugin.
|
6
|
-
|
7
4
|
## Installation
|
8
5
|
Add this line to your application's Gemfile:
|
9
6
|
|
@@ -20,6 +17,17 @@ Or install it yourself as:
|
|
20
17
|
```bash
|
21
18
|
$ gem install rails_com
|
22
19
|
```
|
20
|
+
## Usage
|
21
|
+
How to use my plugin.
|
22
|
+
|
23
|
+
|
24
|
+
### View: add link
|
25
|
+
```erb
|
26
|
+
<%= link_to locales_path, class: 'item', remote: true, id: 'locales_show' do %>
|
27
|
+
<i class="translate icon"></i>
|
28
|
+
<% end %>
|
29
|
+
```
|
30
|
+
|
23
31
|
|
24
32
|
## Contributing
|
25
33
|
Contribution directions go here.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
function timeForLocalized(){
|
2
|
+
$('time[data-localized!="true"]').each(function(){
|
3
|
+
this.textContent = moment.utc(this.textContent).local().format('YYYY-MM-DD HH:mm:ss');
|
4
|
+
this.dataset['localized'] = 'true'
|
5
|
+
})
|
6
|
+
}
|
7
|
+
|
8
|
+
function clickCallback(e) {
|
9
|
+
if (e.target.tagName !== 'A') {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
(new Date).getTimezoneOffset();
|
13
|
+
}
|
14
|
+
|
15
|
+
//document.addEventListener('click', clickCallback, false);
|
16
|
+
|
17
|
+
document.addEventListener('DOMContentLoaded', function() {
|
18
|
+
timeForLocalized()
|
19
|
+
});
|
20
|
+
|
21
|
+
document.addEventListener('turbolinks:load', function() {
|
22
|
+
timeForLocalized()
|
23
|
+
});
|
24
|
+
|
25
|
+
document.addEventListener('turbolinks:request-start', function(event) {
|
26
|
+
var xhr = event.data.xhr;
|
27
|
+
var offset = (new Date).getTimezoneOffset();
|
28
|
+
xhr.setRequestHeader('Utc-Offset', offset);
|
29
|
+
});
|
30
|
+
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
function fetch_xhr_script(url, params){
|
2
|
+
var default_params = {
|
3
|
+
credentials: 'include',
|
4
|
+
headers: {
|
5
|
+
'Accept': 'application/javascript',
|
6
|
+
'X-CSRF-Token': document.head.querySelector("[name=csrf-token]").content
|
7
|
+
}
|
8
|
+
};
|
9
|
+
|
10
|
+
fetch(url, params).then(function(response) {
|
11
|
+
return response.text()
|
12
|
+
}).then(function(text) {
|
13
|
+
var script = document.createElement('script');
|
14
|
+
script.text = text;
|
15
|
+
document.head.appendChild(script).parentNode.removeChild(script);
|
16
|
+
}).catch(function(ex) {
|
17
|
+
console.log('parsing failed', ex)
|
18
|
+
})
|
19
|
+
}
|
20
|
+
|
21
|
+
function listenCheckedIds(name) {
|
22
|
+
var checked = 'input[name="' + name + '"]:checked';
|
23
|
+
var unchecked = 'input[name="' + name + '"][checked!="checked"]';
|
24
|
+
|
25
|
+
window.add_ids = [];
|
26
|
+
window.remove_ids = [];
|
27
|
+
$(checked).change(function(){
|
28
|
+
if(this.checked){
|
29
|
+
var index = window.remove_ids.indexOf(this.value);
|
30
|
+
window.remove_ids.splice(index, 1);
|
31
|
+
} else {
|
32
|
+
window.remove_ids.push(this.value)
|
33
|
+
}
|
34
|
+
});
|
35
|
+
$(unchecked).change(function(){
|
36
|
+
if(this.checked){
|
37
|
+
window.add_ids.push(this.value)
|
38
|
+
} else {
|
39
|
+
var index = window.add_ids.indexOf(this.value);
|
40
|
+
window.add_ids.splice(index, 1);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
45
|
+
function getAddIds(){
|
46
|
+
add_str = window.add_ids.join(',');
|
47
|
+
return add_str;
|
48
|
+
}
|
49
|
+
|
50
|
+
function getRemoveIds(){
|
51
|
+
remove_str = window.remove_ids.join(',');
|
52
|
+
return remove_str
|
53
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CommonController < ApplicationController
|
2
|
+
|
3
|
+
def locales
|
4
|
+
respond_to do |format|
|
5
|
+
format.html
|
6
|
+
format.js
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def not_found
|
11
|
+
params.permit!
|
12
|
+
RailsCom.not_found_logger.info "#{params[:path]}.#{params[:format]}"
|
13
|
+
|
14
|
+
head :not_found
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -5,9 +5,10 @@ module TheCommonApi
|
|
5
5
|
rescue_from 'ActiveRecord::RecordNotFound' do |exp|
|
6
6
|
render json: { error: exp.message, backtrace: exp.backtarce }, status: :not_found
|
7
7
|
end
|
8
|
-
rescue_from 'StandardError' do |exp|
|
9
|
-
|
10
|
-
end
|
8
|
+
# rescue_from 'StandardError' do |exp|
|
9
|
+
# render json: { error: exp.message, backtrace: exp.backtrace }, status: 500
|
10
|
+
# end
|
11
|
+
after_action :wrap_body
|
11
12
|
end
|
12
13
|
|
13
14
|
def process_errors(model)
|
@@ -17,4 +18,15 @@ module TheCommonApi
|
|
17
18
|
}, status: 500
|
18
19
|
end
|
19
20
|
|
21
|
+
def wrap_body
|
22
|
+
if self.response.media_type == 'application/json'
|
23
|
+
begin
|
24
|
+
body = JSON.parse self.response.body
|
25
|
+
rescue JSON::ParserError
|
26
|
+
body = {}
|
27
|
+
end
|
28
|
+
self.response.body = { data: body }.to_json
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
end
|
@@ -9,6 +9,17 @@ module RailsCom::ActiveHelper
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
# active_asserts('active': true, expected: false)
|
13
|
+
def active_asserts(join: true, **options)
|
14
|
+
keys = options.select { |_, v| v }.keys
|
15
|
+
|
16
|
+
if join
|
17
|
+
keys.join(' ')
|
18
|
+
else
|
19
|
+
keys.last.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
12
23
|
# path: active_helper paths: '/work/employees' or active_helper paths: ['/work/employees']
|
13
24
|
# controller: active_helper controllers: 'xxx' or active_helper controllers: ['xxx1', 'admin/xxx2']
|
14
25
|
# action: active_helper 'work/employee': ['index', 'show']
|
@@ -49,20 +60,20 @@ module RailsCom::ActiveHelper
|
|
49
60
|
def filter_params(options = {})
|
50
61
|
except = options.delete(:except)
|
51
62
|
only = options.delete(:only)
|
52
|
-
query = request.GET
|
63
|
+
query = ActionController::Parameters.new(request.GET)
|
53
64
|
|
54
|
-
if only
|
55
|
-
query.
|
65
|
+
if only
|
66
|
+
query = query.permit(only)
|
56
67
|
else
|
57
68
|
excepts = []
|
58
|
-
if except.is_a?
|
69
|
+
if except.is_a?(Array)
|
59
70
|
excepts += except
|
60
|
-
|
71
|
+
elsif except.present?
|
61
72
|
excepts << except
|
62
73
|
end
|
63
74
|
excepts += ['commit', 'utf8', 'page']
|
64
75
|
|
65
|
-
query.except
|
76
|
+
query = query.permit!.except(*excepts)
|
66
77
|
end
|
67
78
|
|
68
79
|
query.merge!(options)
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module RailsComHelper
|
2
2
|
|
3
|
-
def js_load(filename = nil, root:
|
3
|
+
def js_load(filename = nil, root: nil, **options)
|
4
4
|
filename ||= "controllers/#{controller_path}/#{action_name}"
|
5
|
+
root ||= @_rendered_from || Rails.root
|
5
6
|
path = root + 'app/assets/javascripts' + filename.to_s
|
6
7
|
if File.exist?(path.to_s + '.js') || File.exist?(path.to_s + '.js.erb')
|
7
8
|
javascript_include_tag filename, options
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
|
-
def css_load(filename = nil, root:
|
12
|
+
def css_load(filename = nil, root: nil, **options)
|
12
13
|
filename ||= "controllers/#{controller_path}/#{action_name}"
|
14
|
+
root ||= @_rendered_from || Rails.root
|
13
15
|
path = root + 'app/assets/stylesheets' + filename.to_s
|
14
16
|
if File.exist?(path.to_s + '.css')
|
15
17
|
stylesheet_link_tag filename, options
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def js_ready(filename = nil, root:
|
21
|
+
def js_ready(filename = nil, root: nil, **options)
|
20
22
|
filename ||= "controllers/#{controller_path}/#{action_name}.ready"
|
23
|
+
root ||= @_rendered_from || Rails.root
|
21
24
|
path = root + 'app/assets/javascripts' + filename.to_s
|
22
25
|
if File.exist?(path.to_s + '.js') || File.exist?(path.to_s + '.js.erb')
|
23
26
|
javascript_include_tag filename, options
|
data/app/models/state_machine.rb
CHANGED
@@ -9,13 +9,14 @@ module StateMachine
|
|
9
9
|
|
10
10
|
options.each do |k, v|
|
11
11
|
states = k.to_s.pluralize
|
12
|
-
states = self.class.send(states)
|
12
|
+
states = self.class.send(states)
|
13
13
|
|
14
|
-
i = states
|
15
|
-
n = states
|
14
|
+
i = states[self.send(k)]
|
15
|
+
n = states.key(i+1)
|
16
16
|
|
17
17
|
if n == v.to_s
|
18
|
-
|
18
|
+
assign_attributes(k => v)
|
19
|
+
save!
|
19
20
|
else
|
20
21
|
errors.add k, 'Next state is wrong'
|
21
22
|
raise ActiveRecord::Rollback, 'Next state is wrong'
|
@@ -0,0 +1 @@
|
|
1
|
+
Time::DATE_FORMATS[:admin] = '%Y-%m-%d %H:%M:%S'
|
data/config/locales/en.yml
CHANGED
@@ -15,9 +15,11 @@ en:
|
|
15
15
|
other: "Displaying <b>all %{count}</b> %{entry_name}"
|
16
16
|
more_pages:
|
17
17
|
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
select:
|
19
|
+
prompt: "Please select"
|
20
|
+
submit:
|
21
|
+
create: 'Creates %{model}'
|
22
|
+
update: 'Updates %{model}'
|
23
|
+
submit: 'Saves %{model}'
|
24
|
+
q:
|
25
|
+
submit: 'Search'
|