rails_com 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/rails_com_manifest.js +3 -2
  3. data/app/assets/images/verification.jpg +0 -0
  4. data/app/assets/javascripts/rails_com/application.js +3 -0
  5. data/app/assets/stylesheets/rails_com/application.css +4 -0
  6. data/app/controllers/concerns/the_common_api.rb +20 -0
  7. data/app/controllers/the_guards_controller.rb +18 -0
  8. data/app/helpers/rails_com/active_helper.rb +18 -37
  9. data/app/helpers/rails_com_helper.rb +16 -0
  10. data/app/models/state_machine.rb +1 -1
  11. data/app/views/kaminari/_paginator.html.erb +1 -1
  12. data/app/views/layouts/rails_com/application.html.erb +17 -0
  13. data/app/views/the_guards/index.html.erb +18 -0
  14. data/config/locales/en.yml +7 -1
  15. data/config/routes.rb +3 -0
  16. data/lib/assets/javascripts/input-attachment.js +481 -0
  17. data/lib/assets/stylesheets/semantic.css +19466 -0
  18. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot +0 -0
  19. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf +0 -0
  20. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg +2671 -0
  21. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf +0 -0
  22. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff +0 -0
  23. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2 +0 -0
  24. data/lib/nondigest_assets/images/themes/default/assets/images/flags.png +0 -0
  25. data/lib/rails_com/controller_helper.rb +25 -0
  26. data/lib/rails_com/core_ext/hash.rb +1 -0
  27. data/lib/rails_com/core_ext/nil.rb +7 -0
  28. data/lib/rails_com/engine.rb +8 -0
  29. data/lib/rails_com/helpers/qiniu_helper.rb +21 -50
  30. data/lib/rails_com/sprockets/non_digest_assets.rb +34 -0
  31. data/lib/rails_com/sprockets/qiniu_exporter.rb +21 -0
  32. data/lib/rails_com/sprockets.rb +15 -0
  33. data/lib/rails_com/version.rb +1 -1
  34. data/lib/rails_com.rb +6 -4
  35. data/lib/templates/erb/scaffold/_form.html.erb +19 -0
  36. data/lib/templates/erb/scaffold/edit.html.erb +2 -0
  37. data/lib/templates/erb/scaffold/index.html.erb +36 -0
  38. data/lib/templates/erb/scaffold/new.html.erb +1 -0
  39. data/lib/templates/erb/scaffold/show.html.erb +13 -0
  40. data/lib/templates/rails/scaffold_controller/controller.rb +47 -0
  41. metadata +45 -7
  42. data/app/assets/config/qiniu.js +0 -23
  43. data/app/assets/config/qiniu1.js +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9884f6394c3e3e9d704e28b52b564eab818287d3
4
- data.tar.gz: c0b5eb3790e0a67868a44715f2e9c36760ce33c7
3
+ metadata.gz: 32b4755a8bebb55e2b76cf7706a5db5847faf3d3
4
+ data.tar.gz: 353c60cc06071bb72a88ef9c146d2d3ec85369ed
5
5
  SHA512:
6
- metadata.gz: b45dd59723a7532cb40a8001928de34edd568d4d94b0e953012da16d4026ed89671eb6a07a4180366e98b77b101abd0ac427e751780fc81a3b79b385a57f7ce7
7
- data.tar.gz: f58cc13c5ac95755231adc26f9c867e6a3dd24bf291ac4db390eaf52caa1178b3b0e620508b90b051e2c552bef02f75a875a9df44b2a8ebff9b92c40ab50fa00
6
+ metadata.gz: '0384054fc7e6a81ad573089fe6a4b1357dee92dd60325dc5ca0375fe20b024fd64e08d513394c9036968fcea65f047e0bb2b55929af22abb6503b3e508c69728'
7
+ data.tar.gz: b92de35c6e6a552de2140bc4c6812b8098b733f61eb2dfef8df5f1a454a8b92e1dfcda849eb053c1dc68d447432755c79b75e3f3b2d23b63cce21c7330a2fa07
@@ -1,3 +1,4 @@
1
- //# link rails_com/application.css
1
+ //= link rails_com/application.css
2
2
  //= link rails_com/application.js
3
- //= link_tree ../javascripts/controllers .js
3
+
4
+ //= link_tree ../images
Binary file
@@ -0,0 +1,3 @@
1
+ //= require rails-ujs
2
+ //= require turbolinks
3
+ //= require_self
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require semantic
3
+ *= require_self
4
+ */
@@ -0,0 +1,20 @@
1
+ module TheCommonApi
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from 'ActiveRecord::RecordNotFound' do |exp|
6
+ render json: { error: exp.message, backtrace: exp.backtarce }, status: :not_found
7
+ end
8
+ rescue_from 'StandardError' do |exp|
9
+ render json: { error: exp.message, backtrace: exp.backtrace }, status: 500
10
+ end
11
+ end
12
+
13
+ def process_errors(model)
14
+ render json: {
15
+ errors: model.errors.as_json(full_messages: true),
16
+ full_messages: model.errors.full_messages.join(',')
17
+ }, status: 500
18
+ end
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ class TheGuardsController < ApplicationController
2
+ layout 'rails_com/application'
3
+ skip_before_action :require_recaptcha, raise: false
4
+
5
+ def index
6
+
7
+ end
8
+
9
+ def create
10
+ if verify_rucaptcha?
11
+ clear_ip_count
12
+ redirect_to session[:back_to] || root_url
13
+ else
14
+ redirect_to '/the_guards', alert: 'Invalid captcha code.'
15
+ end
16
+ end
17
+
18
+ end
@@ -9,53 +9,34 @@ module RailsCom::ActiveHelper
9
9
  end
10
10
  end
11
11
 
12
- def active_helper(controller: [], path: [], active_class: 'item active', item_class: 'item')
13
- if path.present?
14
- return active_class if path.include?(request.path)
15
- end
16
-
17
- if controller.present?
18
- controller.include?(controller_name) ? active_class : item_class
19
- else
20
- item_class
21
- end
22
- end
23
-
24
- def active_action(active_class: 'item active', item_class: 'item', **options)
25
- ok = false
26
- options.each do |key, value|
27
- if controller_name == key.to_s
28
- ok = true if value.include?(action_name)
12
+ # path: active_helper paths: '/work/employees' or active_helper paths: ['/work/employees']
13
+ # controller: active_helper controllers: 'xxx' or active_helper controllers: ['xxx1', 'admin/xxx2']
14
+ # action: active_helper 'work/employee': ['index', 'show']
15
+ # params: active_params state: 'xxx'
16
+ # active_helper controller: 'users', action: 'show', id: 371
17
+ def active_helper(paths: [], controllers: [], active_class: 'item active', item_class: 'item', **options)
18
+ check_parameters = options.delete(:check_parameters)
19
+
20
+ if paths.present?
21
+ Array(paths).each do |path|
22
+ return active_class if current_page?(path, check_parameters: check_parameters)
29
23
  end
30
24
  end
31
25
 
32
- if ok
33
- active_class
34
- else
35
- item_class
26
+ if controllers.present?
27
+ return active_class if (Array(controllers) & [controller_name, controller_path]).size > 0
36
28
  end
37
- end
38
29
 
39
- # active_page controller: 'users', action: 'show', id: 371
40
- def active_page(options)
41
- active_class = options.delete(:active_class) || 'item active'
42
- item_class = options.delete(:item_class) || 'item'
30
+ return active_class if options.present? && current_page?(options)
43
31
 
44
- options.select { |_, v| v.blank? }.each do |k, v|
45
- if params[k].to_s == v.to_s
46
- return active_class
47
- else
48
- return item_class
49
- end
32
+ options.select { |k, _| [controller_name, controller_path].include?(k.to_s) }.each do |_, value|
33
+ return active_class if value.include?(action_name)
50
34
  end
51
35
 
52
- current_page?(options) ? active_class : item_class
36
+ item_class
53
37
  end
54
38
 
55
- def active_params(options)
56
- active_class = options.delete(:active_class) || 'item active'
57
- item_class = options.delete(:item_class) || 'item'
58
-
39
+ def active_params(active_class: 'item active', item_class: 'item', **options)
59
40
  options.select { |_, v| v.present? }.each do |k, v|
60
41
  if params[k].to_s == v.to_s
61
42
  return active_class
@@ -8,6 +8,22 @@ module RailsComHelper
8
8
  end
9
9
  end
10
10
 
11
+ def css_load(filename = nil, root: Rails.root, **options)
12
+ filename ||= "controllers/#{controller_path}/#{action_name}"
13
+ path = root + 'app/assets/stylesheets' + filename.to_s
14
+ if File.exist?(path.to_s + '.css')
15
+ stylesheet_link_tag filename, options
16
+ end
17
+ end
18
+
19
+ def js_ready(filename = nil, root: Rails.root, **options)
20
+ filename ||= "controllers/#{controller_path}/#{action_name}.ready"
21
+ path = root + 'app/assets/javascripts' + filename.to_s
22
+ if File.exist?(path.to_s + '.js') || File.exist?(path.to_s + '.js.erb')
23
+ javascript_include_tag filename, options
24
+ end
25
+ end
26
+
11
27
  def simple_format_hash(hash_text, options = {})
12
28
  wrapper_tag = options.fetch(:wrapper_tag, :p)
13
29
 
@@ -17,7 +17,7 @@ module StateMachine
17
17
  if n == v.to_s
18
18
  update!(k => states[v])
19
19
  else
20
- errors.add :state, 'Next state is wrong'
20
+ errors.add k, 'Next state is wrong'
21
21
  raise ActiveRecord::Rollback, 'Next state is wrong'
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  <%= paginator.render do %>
2
- <nav class="ui pagination menu">
2
+ <nav class="<%= @options[:class] || 'ui pagination menu' %>">
3
3
  <%= first_page_tag unless current_page.first? %>
4
4
  <%= prev_page_tag unless current_page.first? %>
5
5
  <% each_page do |page| %>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title></title>
6
+ <%= stylesheet_link_tag 'rails_com/application', media: 'all', 'data-turbolinks-track': true %>
7
+ <%= javascript_include_tag 'rails_com/application', 'data-turbolinks-track': true %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+
17
+ </html>
@@ -0,0 +1,18 @@
1
+ <div class="ui basic segment">
2
+ <%= image_tag 'verification.jpg', class: 'ui centered image' %>
3
+ <h3 class="ui green center aligned header">
4
+ 您的请求过于频繁,喝口茶休息一下吧
5
+ </h3>
6
+ <h4 class="ui center aligned header">
7
+ 如果希望继续访问,请输入验证码
8
+
9
+ </h4>
10
+ <div class="ui center aligned basic segment">
11
+ <%= form_tag do %>
12
+ <%= rucaptcha_input_tag(class: 'form-control', placeholder: 'Input Captcha') %>
13
+ <% end %>
14
+ <%= rucaptcha_image_tag(alt: 'Captcha') %>
15
+ </div>
16
+
17
+
18
+ </div>
@@ -14,4 +14,10 @@ en:
14
14
  one: "Displaying <b>1</b> %{entry_name}"
15
15
  other: "Displaying <b>all %{count}</b> %{entry_name}"
16
16
  more_pages:
17
- display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
17
+ display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
18
+ select:
19
+ prompt: "Please select"
20
+ submit:
21
+ create: 'Create %{model}'
22
+ update: 'Update %{model}'
23
+ submit: 'Save %{model}'
data/config/routes.rb CHANGED
@@ -1,2 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+
3
+ resources :the_guards
4
+
2
5
  end