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.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +11 -3
  3. data/app/assets/javascripts/rails_com/application.js +1 -1
  4. data/app/assets/javascripts/rails_com/common.js +32 -0
  5. data/app/assets/javascripts/rails_com/fetch_xhr_script.js +53 -0
  6. data/app/assets/javascripts/rails_com/footer.js +3 -0
  7. data/app/assets/stylesheets/rails_com/application.css +0 -1
  8. data/app/controllers/common_controller.rb +18 -0
  9. data/app/controllers/concerns/the_common_api.rb +15 -3
  10. data/app/helpers/rails_com/active_helper.rb +17 -6
  11. data/app/helpers/rails_com_helper.rb +6 -3
  12. data/app/models/state_machine.rb +5 -4
  13. data/app/views/shared/_alert.html.erb +1 -5
  14. data/app/views/shared/_error_messages.html.erb +1 -7
  15. data/app/views/shared/_locales.html.erb +8 -0
  16. data/config/initializers/time_format.rb +1 -0
  17. data/config/locales/en.yml +8 -6
  18. data/config/routes.rb +7 -0
  19. data/lib/assets/javascripts/semantic.js +11 -0
  20. data/lib/mina/puma.rb +63 -0
  21. data/lib/mina/sidekiq.rb +65 -0
  22. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot +0 -0
  23. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf +0 -0
  24. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg +946 -2670
  25. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf +0 -0
  26. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff +0 -0
  27. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2 +0 -0
  28. data/lib/nondigest_assets/{images → fonts}/themes/default/assets/images/flags.png +0 -0
  29. data/lib/rails_com/controller_helper.rb +26 -1
  30. data/lib/rails_com/controllers.rb +8 -0
  31. data/lib/rails_com/core_ext/nil.rb +1 -1
  32. data/lib/rails_com/helpers/uid_helper.rb +24 -4
  33. data/lib/rails_com/rails_ext/scaffold_generator.rb +14 -0
  34. data/lib/rails_com/rails_ext/template_renderer.rb +22 -0
  35. data/lib/rails_com/routes.rb +12 -8
  36. data/lib/rails_com/sprockets/non_digest_assets.rb +0 -18
  37. data/lib/rails_com/version.rb +1 -1
  38. data/lib/rails_com.rb +11 -2
  39. data/lib/templates/erb/scaffold/_form.html.erb.tt +12 -0
  40. data/lib/templates/erb/scaffold/_search_form.html.erb.tt +7 -0
  41. data/lib/templates/erb/scaffold/edit.html.erb.tt +14 -0
  42. data/lib/templates/erb/scaffold/index.html.erb.tt +43 -0
  43. data/lib/templates/erb/scaffold/new.html.erb.tt +13 -0
  44. data/lib/templates/erb/scaffold/show.html.erb.tt +7 -0
  45. data/lib/templates/rails/scaffold_controller/controller.rb.tt +53 -0
  46. metadata +25 -16
  47. data/lib/assets/stylesheets/semantic.css +0 -19466
  48. data/lib/rails_com/helpers/qiniu_helper.rb +0 -84
  49. data/lib/rails_com/sprockets/qiniu_exporter.rb +0 -21
  50. data/lib/rails_com/sprockets.rb +0 -15
  51. data/lib/templates/erb/scaffold/_form.html.erb +0 -19
  52. data/lib/templates/erb/scaffold/edit.html.erb +0 -2
  53. data/lib/templates/erb/scaffold/index.html.erb +0 -36
  54. data/lib/templates/erb/scaffold/new.html.erb +0 -1
  55. data/lib/templates/erb/scaffold/show.html.erb +0 -13
  56. data/lib/templates/rails/scaffold_controller/controller.rb +0 -47
@@ -1,84 +0,0 @@
1
- module QiniuHelper
2
- extend self
3
-
4
- def download_url(key)
5
- Qiniu::Auth.authorize_download_url_2(config['host'], key)
6
- end
7
-
8
- def qiniu_url(key)
9
- config['host'] << '/' unless config['host'].end_with? '/'
10
- config['host'] + key.to_s
11
- end
12
-
13
- def generate_uptoken(key = nil, **options)
14
- put_policy = Qiniu::Auth::PutPolicy.new(config['bucket'], key)
15
- options.slice(*Qiniu::Auth::PutPolicy::PARAMS.keys).each do |k, v|
16
- put_policy.send(k.to_s + '=', v)
17
- end
18
- @uptoken = Qiniu::Auth.generate_uptoken(put_policy)
19
- end
20
-
21
- def upload(local_file, key = nil, **options)
22
- code, result, response_headers = upload_verbose(local_file, key, options)
23
- result['key']
24
- end
25
-
26
- def upload_verbose(local_file, key = nil, **options)
27
- code, result, response_headers = Qiniu::Storage.upload_with_token_2(
28
- generate_uptoken(key, options),
29
- local_file,
30
- key,
31
- nil,
32
- bucket: config['bucket']
33
- )
34
- end
35
-
36
- def delete(key)
37
- code, result, response_headers = Qiniu::Storage.delete(
38
- config['bucket'],
39
- key
40
- )
41
- code
42
- end
43
-
44
- def list(prefix = '')
45
- list_policy = Qiniu::Storage::ListPolicy.new(config['bucket'], 10, prefix, '/')
46
- code, result, response_headers, s, d = Qiniu::Storage.list(list_policy)
47
- result['items']
48
- end
49
-
50
- def last(prefix = '')
51
- ary = (0..9).to_a.reverse
52
- search = prefix
53
- result = nil
54
-
55
- while true do
56
- break result if result
57
- ary.each_with_index do |value, index|
58
- search.sub! /\d$/, value.to_s
59
- list = self.list(search)
60
-
61
- puts 'index: ' + index.to_s
62
- puts 'search: ' + search
63
- puts 'count: ' + list.size.to_s
64
- puts '-------------'
65
-
66
- if list.blank?
67
- next
68
- elsif list.size > 1
69
- search << '9'
70
- break
71
- elsif list.size == 1
72
- break result = list[0]['key']
73
- end
74
- end
75
- end
76
-
77
- result
78
- end
79
-
80
- def config
81
- @config ||= Rails.application.config_for('qiniu')
82
- end
83
-
84
- end
@@ -1,21 +0,0 @@
1
- require 'sprockets/exporters/base'
2
-
3
- # Writes a an asset file to Qiniu
4
- class QiniuExporter < Sprockets::Exporters::Base
5
-
6
- def skip?(logger)
7
- if Sprockets.config[:sync].to_s == 'qiniu'
8
- logger.info "==> To Upload to Qiniu: #{ target }"
9
- false
10
- else
11
- true
12
- end
13
- end
14
-
15
- def call
16
- QiniuHelper.upload target, 'assets/' + asset.digest_path.to_s
17
- end
18
-
19
- end
20
-
21
- Sprockets.register_exporter '*/*', QiniuExporter
@@ -1,15 +0,0 @@
1
- require 'rails_com/sprockets/non_digest_assets'
2
- require 'rails_com/sprockets/qiniu_exporter'
3
-
4
-
5
- module Sprockets
6
-
7
- def self.sync
8
- config[:sync]
9
- end
10
-
11
- def self.sync=(sync)
12
- self.config = hash_reassoc(config, :sync) { sync.dup }
13
- end
14
-
15
- end
@@ -1,19 +0,0 @@
1
- <%
2
- form_model_name = "@#{file_name}"
3
- if controller_class_name.include?('::')
4
- namespace = controller_class_name.split('::').first.downcase
5
- form_model_name = "[:#{namespace},@#{file_name}]"
6
- end
7
- %>
8
- <%%= simple_form_for(<%= form_model_name %>) do |f| %>
9
- <%%= render "/shared/error_messages", target: @<%= file_name %> %>
10
- <% for attribute in attributes -%>
11
- <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
12
- <% end -%>
13
- <div>oososos</div>
14
- <div class="form-group">
15
- <div class="col-md-10 col-sm-offset-2">
16
- <%%= f.submit t("common.save"), class: "btn btn-primary" %> or <%%= link_to t("common.cancel"), <%= index_helper %>_path %>
17
- </div>
18
- </div>
19
- <%% end %>
@@ -1,2 +0,0 @@
1
- <%%= render 'form' %>
2
-
@@ -1,36 +0,0 @@
1
- <%% content_for :sitemap do %>
2
- <span class="current"><%%= t("activerecord.models.<%= file_name %>") %></span>
3
- <%% end %>
4
-
5
- <%%= render 'base' %>
6
- <h1><%%= t("activerecord.models.<%= file_name %>") %></h1>
7
-
8
- <div class="toolbar">
9
- <a href="<%%= new_<%= singular_table_name %>_path %>" class="btn btn-sm btn-success">新建</a>
10
- </div>
11
-
12
- <div id="<%= plural_table_name %>">
13
- <table class="table table-bordered table-striped table-condensed">
14
- <tr class="head">
15
- <td>编号</td>
16
- <% attributes.each do |attr| -%>
17
- <td><%%= t("activerecord.attributes.<%= file_name %>.<%= attr.name %>") %></td>
18
- <% end -%>
19
- <td>创建时间</td>
20
- <td class="opts"></td>
21
- </tr>
22
- <%% @<%= plural_file_name %>.each do |item| %>
23
- <tr class="<%%= cycle("","even") %>">
24
- <td><%%= item.id %></td>
25
- <% attributes.each do |attr| -%>
26
- <td><%%= item.<%= attr.name %> %></td>
27
- <% end -%>
28
- <td><%%= l(item.created_at, format: :long) %></td>
29
- <td>
30
- <%%= link_to "", edit_<%= singular_table_name %>_path(item.id), class: "fa fa-pencil" %>
31
- <%%= link_to "", <%= singular_table_name %>_path(item.id), method: :delete, 'data-confirm' => '确定要删除吗?', class: "fa fa-trash" %>
32
- </td>
33
- </tr>
34
- <%% end %>
35
- </table>
36
- </div>
@@ -1 +0,0 @@
1
- <%%= render 'form' %>
@@ -1,13 +0,0 @@
1
- <div class="toolbar">
2
- <%%= link_to '修改', edit_<%= singular_table_name %>_path(@<%= file_name %>), class: "btn btn-sm btn-success" %>
3
- <%%= link_to '返回', <%= index_helper %>_path, class: "btn btn-sm btn-default" %>
4
- </div>
5
-
6
- <div id="<%= singular_table_name %>">
7
- <% for attribute in attributes -%>
8
- <p>
9
- <b><%= attribute.human_name %>:</b>
10
- <%%= @<%= file_name %>.<%= attribute.name %> %>
11
- </p>
12
- <% end -%>
13
- </div>
@@ -1,47 +0,0 @@
1
- class <%= controller_class_name %>Controller < <%= controller_class_name.include?('::') == true ? "#{controller_class_name.split('::').first}::" : '' %>ApplicationController
2
- before_action :set_<%= file_name %>, only: [:show, :edit, :update, :destroy]
3
-
4
- def index
5
- @<%= plural_file_name %> = <%= file_name.camelize %>.desc('_id')
6
- @<%= plural_file_name %> = @<%= plural_file_name %>.paginate(page: params[:page], per_page: 30)
7
- end
8
-
9
- def show
10
- end
11
-
12
- def new
13
- @<%= file_name %> = <%= orm_class.build(file_name.camelize) %>
14
- end
15
-
16
- def edit
17
- end
18
-
19
- def create
20
- @<%= file_name %> = <%= orm_class.build(file_name.camelize, "params[:#{file_name}].permit!") %>
21
-
22
- if @<%= file_name %>.save
23
- redirect_to(<%= index_helper %>_path, notice: '<%= human_name %> 创建成功。')
24
- else
25
- render action: "new"
26
- end
27
- end
28
-
29
- def update
30
- if @<%= file_name %>.update_attributes(params[:<%= file_name %>].permit!)
31
- redirect_to(<%= index_helper %>_path, notice: '<%= human_name %> 更新成功。')
32
- else
33
- render action: "edit"
34
- end
35
- end
36
-
37
- def destroy
38
- @<%= file_name %>.destroy
39
- redirect_to(<%= index_helper %>_path, notice: "删除成功。")
40
- end
41
-
42
- private
43
-
44
- def set_<%= file_name %>
45
- @<%= file_name %> = <%= orm_class.find(file_name.camelize, "params[:id]") %>
46
- end
47
- end