rails_com 1.2.1 → 1.2.2

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +165 -0
  3. data/README.md +18 -26
  4. data/Rakefile +6 -9
  5. data/app/assets/config/rails_com_manifest.js +2 -0
  6. data/app/assets/javascripts/controllers/active_storage_ext/videos/show.ready.js +1 -0
  7. data/app/assets/javascripts/rails_com/common.js +3 -0
  8. data/app/assets/javascripts/rails_com/fetch_xhr_script.js +3 -2
  9. data/app/assets/stylesheets/controllers/active_storage_ext/videos/show.css +7 -0
  10. data/app/assets/stylesheets/controllers/active_storage_ext/videos/transfer.css +4 -0
  11. data/app/controllers/active_storage/attachments_controller.rb +13 -0
  12. data/app/controllers/active_storage_ext/videos_controller.rb +25 -0
  13. data/app/controllers/concerns/the_common_api.rb +7 -1
  14. data/app/helpers/rails_com/active_helper.rb +14 -10
  15. data/app/helpers/rails_com/assets_helper.rb +40 -14
  16. data/app/helpers/rails_com/format_helper.rb +37 -0
  17. data/app/models/state_machine.rb +10 -6
  18. data/app/views/active_storage/attachments/_image_item.html.erb +6 -0
  19. data/app/views/active_storage/attachments/_list.html.erb +28 -0
  20. data/app/views/active_storage/attachments/_list_edit.html.erb +25 -0
  21. data/app/views/active_storage/attachments/_list_form.html.erb +28 -0
  22. data/app/views/active_storage/attachments/_video_item.html.erb +6 -0
  23. data/app/views/active_storage/attachments/destroy.js.erb +1 -0
  24. data/app/views/active_storage_ext/videos/show.html.erb +6 -0
  25. data/app/views/kaminari/_next_page.html.erb +1 -1
  26. data/app/views/kaminari/_prev_page.html.erb +1 -1
  27. data/app/views/shared/_error_messages.html.erb +1 -1
  28. data/config/locales/en.yml +5 -0
  29. data/config/locales/zh.yml +5 -0
  30. data/config/routes.rb +10 -5
  31. data/lib/assets/javascripts/input-attachment.js +83 -22
  32. data/lib/mina/git2.rb +59 -0
  33. data/lib/rails_com.rb +22 -12
  34. data/lib/rails_com/config.rb +3 -1
  35. data/lib/rails_com/core_ext/array.rb +35 -17
  36. data/lib/rails_com/core_ext/date.rb +24 -0
  37. data/lib/rails_com/core_ext/numeric.rb +11 -0
  38. data/lib/rails_com/core_ext/string.rb +15 -0
  39. data/lib/rails_com/engine.rb +23 -11
  40. data/lib/rails_com/{controller_helper.rb → helpers/controller_helper.rb} +0 -20
  41. data/lib/rails_com/{model_helper.rb → helpers/model_helper.rb} +3 -3
  42. data/lib/rails_com/{controllers.rb → meta/controllers.rb} +0 -0
  43. data/lib/rails_com/{models.rb → meta/models.rb} +1 -0
  44. data/lib/rails_com/{routes.rb → meta/routes.rb} +9 -0
  45. data/lib/rails_com/rails_ext/activestorage_attached.rb +5 -5
  46. data/lib/rails_com/rails_ext/attachment_transfer.rb +40 -0
  47. data/lib/rails_com/rails_ext/named_base.rb +9 -0
  48. data/lib/rails_com/rails_ext/template_renderer.rb +18 -1
  49. data/lib/rails_com/rails_ext/video_response.rb +28 -0
  50. data/lib/{utils → rails_com/utils}/ip_helper.rb +0 -0
  51. data/lib/rails_com/{helpers → utils}/jobber.rb +0 -0
  52. data/lib/rails_com/utils/num_helper.rb +45 -0
  53. data/lib/rails_com/{setting.rb → utils/setting.rb} +0 -0
  54. data/lib/rails_com/utils/time_helper.rb +58 -0
  55. data/lib/rails_com/{helpers → utils}/uid_helper.rb +0 -0
  56. data/lib/rails_com/version.rb +1 -1
  57. data/lib/templates/erb/scaffold/_form.html.erb.tt +2 -2
  58. data/lib/templates/erb/scaffold/index.html.erb.tt +21 -13
  59. data/lib/templates/erb/scaffold/show.html.erb.tt +14 -5
  60. data/lib/templates/rails/scaffold_controller/api_controller.rb.tt +48 -0
  61. data/lib/templates/rails/scaffold_controller/controller.rb.tt +16 -15
  62. metadata +45 -35
  63. data/MIT-LICENSE +0 -20
  64. data/app/controllers/common_controller.rb +0 -10
  65. data/app/controllers/the_guards_controller.rb +0 -18
  66. data/app/helpers/rails_com/common_helper.rb +0 -13
  67. data/app/views/the_guards/index.html.erb +0 -18
  68. data/lib/utils/time_helper.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ffa9f1ff257d36fdc9bb11415039affae4ee7a1589f7c15f565e911ca6fe33a
4
- data.tar.gz: 36054a13e2f3a8b7ea8c8130dcb16185612bc8b575c701eaaf0630b6c8f0ce0c
3
+ metadata.gz: c54bcd9f05cfb6a9d5b1199c293866a7076a44522650d2801594567de4c10126
4
+ data.tar.gz: f41944cdcac6ff2100ff828f32892ee528ff5cc365a9dd9ececedfa8b0b94a02
5
5
  SHA512:
6
- metadata.gz: 27c0ff46020d0a06076a4c085deea1ce604434b97836232c3ccea537b05b20c7be7960cf2dad3786dfa365f1a85994e7f4b8bc68e9a759c7dd8e598a98e31f95
7
- data.tar.gz: 0d745dbbe1560f2ccfb5fe2a6172ef3180903bec46aa8f40b59d864bb9b447ae8157719c7ed05822086c468a27e82282085e02709720357534af651c247ba130
6
+ metadata.gz: 422d7410cbd9d0511506ff8a6ffcfe80151fe2319515a88386ed6d084bda156d138b98827b3fa6ef01212029cf4aa319337a3760a39ed923b3dae807370dfcdc
7
+ data.tar.gz: 4ef5503d7a5987eae283234e681a6b8e10a0c2bdd1be62f538f5cfbb749f645b817ab52d6e146c5e902a2b94d7d1abd66f91a1183a0a46a5f71f34ff07bb0084
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2018 Mingyuan Qin.
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md CHANGED
@@ -1,38 +1,30 @@
1
1
  # RailsCom
2
- Rails Common engine, with many sugars!
2
+ Rails 通用基础库
3
3
 
4
- ## Installation
5
- Add this line to your application's Gemfile:
6
-
7
- ```ruby
8
- gem 'rails_com'
9
- ```
10
-
11
- And then execute:
12
- ```bash
13
- $ bundle
14
- ```
15
-
16
- Or install it yourself as:
17
- ```bash
18
- $ gem install rails_com
19
- ```
20
- ## Features
4
+ ## 说明
21
5
  * examples: puma, configs etc.
22
6
  * rails and ruby core extension;
23
7
  * methods deal rails model/controller/routes etc.
24
8
  * some helpers, for generator uuid based on time and more;
25
9
 
26
- ### View: add link
10
+ ## Module
11
+ * Ruby core extension
12
+ * Rails meta information: Controller/Model/Routes
13
+ * Rails core extension
14
+ - ActiveStorage sync with url
15
+ - ActiveStorage copy to mirror
16
+ * Utils
17
+ - UidHelper
18
+ - TimeHelper
19
+ - Jobber
20
+ - IpHelper
21
+
22
+ ### Locals support
23
+
27
24
  ```erb
28
- <%= link_to locales_path, class: 'item', remote: true, id: 'locales_show' do %>
29
- <i class="translate icon"></i>
30
- <% end %>
25
+ <%= render 'shared/locales' %>
31
26
  ```
32
27
 
33
28
 
34
- ## Contributing
35
- Contribution directions go here.
36
-
37
29
  ## License
38
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
30
+ The gem is available as open source under the terms of the [LGPL License](https://opensource.org/licenses/LGPL-3.0).
data/Rakefile CHANGED
@@ -4,26 +4,23 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
+ require 'sdoc'
7
8
  require 'rdoc/task'
8
9
 
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'RailsCom'
12
- rdoc.options << '--line-numbers'
10
+ RDoc::Task.new(:sdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'docs'
12
+ rdoc.title = 'RailsCom'
13
+ rdoc.options << '--format=sdoc'
14
+ rdoc.template = 'rails'
13
15
  rdoc.rdoc_files.include('README.md')
14
16
  rdoc.rdoc_files.include('lib/**/*.rb')
15
17
  end
16
18
 
17
19
  APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
20
  load 'rails/tasks/engine.rake'
19
-
20
-
21
21
  load 'rails/tasks/statistics.rake'
22
22
 
23
-
24
-
25
23
  require 'bundler/gem_tasks'
26
-
27
24
  require 'rake/testtask'
28
25
 
29
26
  Rake::TestTask.new(:test) do |t|
@@ -1,4 +1,6 @@
1
1
  //= link rails_com/application.css
2
2
  //= link rails_com/application.js
3
3
 
4
+ //= link_tree ../javascripts/controllers .js
5
+ //= link_tree ../stylesheets/controllers .css
4
6
  //= link_tree ../images
@@ -0,0 +1 @@
1
+ //# require video.js/dist/video.js
@@ -24,6 +24,9 @@ document.addEventListener('DOMContentLoaded', function() {
24
24
  document.addEventListener('turbolinks:load', function() {
25
25
  timeForLocalized()
26
26
  });
27
+ document.addEventListener('turbolinks:visit', function() {
28
+ timeForLocalized()
29
+ });
27
30
 
28
31
  document.addEventListener('turbolinks:request-start', function(event) {
29
32
  var xhr = event.data.xhr;
@@ -2,12 +2,13 @@ function fetch_xhr_script(url, params){
2
2
  var default_params = {
3
3
  credentials: 'include',
4
4
  headers: {
5
- 'Accept': 'application/javascript',
5
+ Accept: 'application/javascript',
6
6
  'X-CSRF-Token': document.head.querySelector("[name=csrf-token]").content
7
7
  }
8
8
  };
9
+ var _params = Object.assign(default_params, params)
9
10
 
10
- fetch(url, params).then(function(response) {
11
+ fetch(url, _params).then(function(response) {
11
12
  return response.text();
12
13
  }).then(function(text) {
13
14
  var script = document.createElement('script');
@@ -0,0 +1,7 @@
1
+ /*
2
+ *# require video.js/dist/video-js.css
3
+ */
4
+
5
+ video {
6
+ max-width: 1127px;
7
+ }
@@ -0,0 +1,13 @@
1
+ class ActiveStorage::AttachmentsController < ActiveStorage::BaseController
2
+ before_action :set_attachment, only: [:destroy]
3
+
4
+ def destroy
5
+ @attachment.purge
6
+ end
7
+
8
+ private
9
+ def set_attachment
10
+ @attachment = ActiveStorage::Attachment.find(params[:id])
11
+ end
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ class ActiveStorageExt::VideosController < RailsCom.config.app_class.constantize
2
+ before_action :set_video, only: [:show, :transfer]
3
+ before_action do
4
+ ActiveStorage::Current.host = request.base_url
5
+ end
6
+
7
+ def show
8
+ expires_in ActiveStorage::Blob.service.url_expires_in
9
+ end
10
+
11
+ def transfer
12
+ attached = @attachment.transfer_faststart
13
+ @video = attached.blob
14
+
15
+ flash[:notice] = 'well done!'
16
+ render 'show'
17
+ end
18
+
19
+ private
20
+ def set_video
21
+ @attachment = ActiveStorage::Attachment.find(params[:id])
22
+ @video = @attachment.blob
23
+ end
24
+
25
+ end
@@ -5,10 +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
+
8
9
  # rescue_from 'StandardError' do |exp|
9
10
  # render json: { error: exp.message, backtrace: exp.backtrace }, status: 500
10
11
  # end
11
- after_action :wrap_body
12
12
  end
13
13
 
14
14
  def process_errors(model)
@@ -18,6 +18,7 @@ module TheCommonApi
18
18
  }, status: 200
19
19
  end
20
20
 
21
+ # used after_action :warp_body
21
22
  def wrap_body
22
23
  if self.response.media_type == 'application/json'
23
24
  begin
@@ -29,4 +30,9 @@ module TheCommonApi
29
30
  end
30
31
  end
31
32
 
33
+ # process_js
34
+ def process_js
35
+
36
+ end
37
+
32
38
  end
@@ -21,12 +21,13 @@ module RailsCom::ActiveHelper
21
21
  end
22
22
  end
23
23
 
24
- # path: active_helper paths: '/work/employees' or active_helper paths: ['/work/employees']
25
- # controller: active_helper controllers: 'xxx' or active_helper controllers: ['xxx1', 'admin/xxx2']
24
+ # paths: active_helper paths: '/work/employees' or active_helper paths: ['/work/employees']
25
+ # controllers: active_helper controllers: 'xxx' or active_helper controllers: ['xxx1', 'admin/xxx2']
26
+ # modules: active_helper modules: 'admin/oa'
26
27
  # action: active_helper 'work/employee': ['index', 'show']
27
28
  # params: active_params state: 'xxx'
28
29
  # active_helper controller: 'users', action: 'show', id: 371
29
- def active_helper(paths: [], controllers: [], active_class: 'item active', item_class: 'item', **options)
30
+ def active_helper(paths: [], controllers: [], modules: [], active_class: 'item active', item_class: 'item', **options)
30
31
  check_parameters = options.delete(:check_parameters)
31
32
 
32
33
  if paths.present?
@@ -39,10 +40,17 @@ module RailsCom::ActiveHelper
39
40
  return active_class if (Array(controllers) & [controller_name, controller_path]).size > 0
40
41
  end
41
42
 
43
+ if modules.present?
44
+ this_modules = controller_path.split('/')
45
+ this_modules.pop
46
+ _this_modules = this_modules.map.with_index { |_, index| this_modules[0, index + 1].join('/') }
47
+ return active_class if (Array(modules) & _this_modules).size > 0
48
+ end
49
+
42
50
  return active_class if options.present? && current_page?(options)
43
51
 
44
52
  options.select { |k, _| [controller_name, controller_path].include?(k.to_s) }.each do |_, value|
45
- return active_class if value.include?(action_name)
53
+ return active_class if Array(value).include?(action_name)
46
54
  end
47
55
 
48
56
  item_class
@@ -62,22 +70,18 @@ module RailsCom::ActiveHelper
62
70
  except = options.delete(:except)
63
71
  only = options.delete(:only)
64
72
  query = ActionController::Parameters.new(request.GET)
73
+ query.merge!(options)
65
74
 
66
75
  if only
67
76
  query = query.permit(only)
68
77
  else
69
78
  excepts = []
70
- if except.is_a?(Array)
71
- excepts += except
72
- elsif except.present?
73
- excepts << except
74
- end
79
+ excepts += (Array(except).map(&:to_s) & request.GET.keys)
75
80
  excepts += ['commit', 'utf8', 'page']
76
81
 
77
82
  query = query.permit!.except(*excepts)
78
83
  end
79
84
 
80
- query.merge!(options)
81
85
  query.reject! { |_, value| value.blank? }
82
86
  query
83
87
  end