rails_com 1.2.5 → 1.2.6

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rails_com/application.js +11 -27
  3. data/app/assets/javascripts/rails_com/attachment.js +24 -19
  4. data/app/assets/javascripts/rails_com/fetch_xhr_script.js +13 -2
  5. data/app/assets/javascripts/rails_com/footer.js +7 -1
  6. data/app/assets/javascripts/rails_com/picture.js +1 -0
  7. data/app/assets/javascripts/rails_com/time_local.js +10 -0
  8. data/app/controllers/active_storage_ext/admin/blob_defaults_controller.rb +2 -1
  9. data/app/controllers/concerns/rails_common_api.rb +25 -15
  10. data/app/controllers/concerns/rails_common_controller.rb +46 -0
  11. data/app/helpers/rails_com/assets_helper.rb +32 -14
  12. data/app/models/active_storage/blob_default.rb +19 -0
  13. data/app/views/active_storage_ext/admin/blob_defaults/_form.html.erb +1 -0
  14. data/app/views/active_storage_ext/admin/blob_defaults/index.html.erb +3 -2
  15. data/app/views/active_storage_ext/attachments/_default_image_item.html.erb +9 -1
  16. data/app/views/active_storage_ext/attachments/_list_edit.html.erb +11 -9
  17. data/app/views/active_storage_ext/attachments/_list_field.html.erb +6 -0
  18. data/db/migrate/20181012025833_rails_com_init.rb +1 -0
  19. data/lib/active_record/type/i18n.rb +19 -0
  20. data/lib/rails_com.rb +11 -21
  21. data/lib/rails_com/action_controller.rb +3 -0
  22. data/lib/rails_com/{helpers → action_controller}/controller_helper.rb +8 -9
  23. data/lib/rails_com/{rails_ext → action_controller}/errors.rb +0 -0
  24. data/lib/rails_com/action_controller/parameters.rb +16 -0
  25. data/lib/rails_com/action_view.rb +2 -0
  26. data/lib/rails_com/{rails_ext → action_view}/template_renderer.rb +5 -17
  27. data/lib/rails_com/{rails_ext → action_view}/translation_helper.rb +3 -1
  28. data/lib/rails_com/active_record.rb +3 -0
  29. data/lib/rails_com/{helpers → active_record}/model_helper.rb +0 -0
  30. data/lib/rails_com/{rails_ext → active_record}/persistence_sneakily.rb +0 -0
  31. data/lib/rails_com/active_record/translation.rb +66 -0
  32. data/lib/rails_com/active_storage.rb +4 -0
  33. data/lib/rails_com/{rails_ext → active_storage}/activestorage_attached.rb +1 -0
  34. data/lib/rails_com/active_storage/attached_macros.rb +20 -0
  35. data/lib/rails_com/{rails_ext → active_storage}/attachment_transfer.rb +4 -2
  36. data/lib/rails_com/active_storage/blob_ext.rb +34 -0
  37. data/lib/rails_com/{rails_ext → active_storage}/video_response.rb +2 -1
  38. data/lib/rails_com/core.rb +7 -0
  39. data/lib/rails_com/{core_ext → core}/array.rb +0 -0
  40. data/lib/rails_com/{core_ext → core}/date.rb +0 -0
  41. data/lib/rails_com/{core_ext → core}/hash.rb +0 -0
  42. data/lib/rails_com/{core_ext → core}/nil.rb +0 -0
  43. data/lib/rails_com/{core_ext → core}/numeric.rb +0 -0
  44. data/lib/rails_com/{core_ext → core}/string.rb +0 -0
  45. data/lib/rails_com/engine.rb +9 -4
  46. data/lib/rails_com/{rails_ext → generators}/named_base.rb +0 -0
  47. data/lib/rails_com/{rails_ext → generators}/scaffold_generator.rb +2 -2
  48. data/lib/rails_com/utils/uid_helper.rb +7 -1
  49. data/lib/rails_com/version.rb +1 -1
  50. data/lib/templates/erb/scaffold/{_search_form.html.erb.tt → _filter.html.erb.tt} +3 -0
  51. data/lib/templates/erb/scaffold/index.html.erb.tt +2 -4
  52. metadata +54 -23
  53. data/app/views/active_storage_ext/attachments/_list_form.html.erb +0 -28
  54. data/lib/rails_com/rails_ext/attached_macros.rb +0 -21
@@ -1,4 +1,4 @@
1
- module VideoResponse
1
+ module RailsCom::VideoResponse
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
@@ -26,3 +26,4 @@ module VideoResponse
26
26
 
27
27
  end
28
28
 
29
+ ActiveStorage::DiskController.include RailsCom::VideoResponse
@@ -0,0 +1,7 @@
1
+ # Ruby core extension
2
+ require 'rails_com/core/hash'
3
+ require 'rails_com/core/nil'
4
+ require 'rails_com/core/array'
5
+ require 'rails_com/core/date'
6
+ require 'rails_com/core/numeric'
7
+ require 'rails_com/core/string'
File without changes
File without changes
File without changes
@@ -11,6 +11,9 @@ class RailsCom::Engine < ::Rails::Engine #:nodoc:
11
11
 
12
12
  initializer 'rails_com.assets.precompile' do |app|
13
13
  app.config.assets.precompile += ['rails_com_manifest.js']
14
+ app.config.content_security_policy_nonce_generator = -> request {
15
+ request.headers['X-Csp-Nonce'] || SecureRandom.base64(16)
16
+ }
14
17
  end
15
18
 
16
19
  initializer 'rails_com.add_assets_templates' do |app|
@@ -18,10 +21,12 @@ class RailsCom::Engine < ::Rails::Engine #:nodoc:
18
21
  end
19
22
 
20
23
  initializer 'rails_com.add_activestorage' do |app|
21
- require 'rails_com/rails_ext/attached_macros'
22
- ActiveStorage::DiskController.include VideoResponse
23
- ActiveStorage::Attachment.include AttachmentTransfer
24
- ActiveStorage::Attached::One.prepend RailsExt::AttachedOne
24
+ require 'rails_com/active_storage'
25
+ config_choice = Rails.configuration.active_storage.private_service
26
+ if config_choice
27
+ configs = Rails.configuration.active_storage.service_configurations
28
+ ActiveStorage::Blob.private_service = ActiveStorage::Service.configure config_choice, configs
29
+ end
25
30
  end
26
31
 
27
32
  end
@@ -2,12 +2,12 @@ require 'rails/generators'
2
2
  require 'rails/generators/erb/scaffold/scaffold_generator'
3
3
 
4
4
  class Erb::Generators::ScaffoldGenerator
5
- source_root File.expand_path('../../../templates/erb/scaffold', __FILE__)
5
+ source_root File.expand_path('../../templates/erb/scaffold', __dir__)
6
6
 
7
7
  undef available_views
8
8
  private
9
9
  def available_views
10
- ['index', 'edit', 'show', 'new', '_form', '_search_form']
10
+ ['index', 'edit', 'show', 'new', '_form', '_filter']
11
11
  end
12
12
 
13
13
  end
@@ -19,6 +19,12 @@ module UidHelper
19
19
  uuid str.to_i, prefix, suffix
20
20
  end
21
21
 
22
+ def usec_uuid(prefix = '', suffix = rand_string(2))
23
+ time = Time.now
24
+ str = time.to_i.to_s + time.usec.to_s
25
+ uuid str.to_i, prefix, suffix
26
+ end
27
+
22
28
  def sec_uuid(prefix = '', suffix = rand_string(2))
23
29
  time = Time.now
24
30
  uuid time.to_i, prefix, suffix
@@ -48,4 +54,4 @@ module UidHelper
48
54
  len.times.map { ((0..9).to_a + ('A'..'Z').to_a).sample }.join
49
55
  end
50
56
 
51
- end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsCom #:nodoc:
2
- VERSION = '1.2.5'
2
+ VERSION = '1.2.6'
3
3
  end
@@ -1,7 +1,10 @@
1
+ <div class="ui attached segment">
2
+
1
3
  <%%= search_form_with do |f| %>
2
4
  <div class="fields">
3
5
  <%%= f.submit 'Search' %>
4
6
  </div>
5
7
  <%% end %>
6
8
 
9
+ </div>
7
10
 
@@ -7,9 +7,7 @@
7
7
  </div>
8
8
  </div>
9
9
 
10
- <div class="ui attached segment">
11
- <%%= render 'search_form' %>
12
- </div>
10
+ <%%= render 'filter' %>
13
11
 
14
12
  <table class="ui bottom attached table">
15
13
  <thead>
@@ -44,4 +42,4 @@
44
42
  </tbody>
45
43
  </table>
46
44
 
47
- <%%= paginate @<%= plural_name %> %>
45
+ <%%= paginate @<%= plural_name %> %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - qinmingyuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.16'
40
+ - - "<="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0.16'
50
+ - - "<="
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
33
53
  description: Common utils for Rails Application
34
54
  email:
35
55
  - mingyuan0715@foxmail.com
@@ -51,6 +71,7 @@ files:
51
71
  - app/assets/javascripts/rails_com/footer.js
52
72
  - app/assets/javascripts/rails_com/picture.js
53
73
  - app/assets/javascripts/rails_com/sidebar.js
74
+ - app/assets/javascripts/rails_com/time_local.js
54
75
  - app/assets/stylesheets/controllers/active_storage_ext/videos/show.css
55
76
  - app/assets/stylesheets/controllers/active_storage_ext/videos/transfer.css
56
77
  - app/assets/stylesheets/rails_com/application.css
@@ -61,6 +82,7 @@ files:
61
82
  - app/controllers/active_storage_ext/audios_controller.rb
62
83
  - app/controllers/active_storage_ext/videos_controller.rb
63
84
  - app/controllers/concerns/rails_common_api.rb
85
+ - app/controllers/concerns/rails_common_controller.rb
64
86
  - app/controllers/concerns/rails_common_xhr.rb
65
87
  - app/helpers/rails_com/active_helper.rb
66
88
  - app/helpers/rails_com/assets_helper.rb
@@ -85,7 +107,7 @@ files:
85
107
  - app/views/active_storage_ext/attachments/_image_item.html.erb
86
108
  - app/views/active_storage_ext/attachments/_list.html.erb
87
109
  - app/views/active_storage_ext/attachments/_list_edit.html.erb
88
- - app/views/active_storage_ext/attachments/_list_form.html.erb
110
+ - app/views/active_storage_ext/attachments/_list_field.html.erb
89
111
  - app/views/active_storage_ext/attachments/_video_item.html.erb
90
112
  - app/views/active_storage_ext/audios/show.html.erb
91
113
  - app/views/active_storage_ext/videos/show.html.erb
@@ -105,6 +127,7 @@ files:
105
127
  - config/locales/zh.yml
106
128
  - config/routes.rb
107
129
  - db/migrate/20181012025833_rails_com_init.rb
130
+ - lib/active_record/type/i18n.rb
108
131
  - lib/generators/doc_model_generator.rb
109
132
  - lib/generators/doc_models_generator.rb
110
133
  - lib/generators/templates/model.erb
@@ -113,29 +136,37 @@ files:
113
136
  - lib/mina/sidekiq.rb
114
137
  - lib/mina/whenever.rb
115
138
  - lib/rails_com.rb
139
+ - lib/rails_com/action_controller.rb
140
+ - lib/rails_com/action_controller/controller_helper.rb
141
+ - lib/rails_com/action_controller/errors.rb
142
+ - lib/rails_com/action_controller/parameters.rb
143
+ - lib/rails_com/action_view.rb
144
+ - lib/rails_com/action_view/template_renderer.rb
145
+ - lib/rails_com/action_view/translation_helper.rb
146
+ - lib/rails_com/active_record.rb
147
+ - lib/rails_com/active_record/model_helper.rb
148
+ - lib/rails_com/active_record/persistence_sneakily.rb
149
+ - lib/rails_com/active_record/translation.rb
150
+ - lib/rails_com/active_storage.rb
151
+ - lib/rails_com/active_storage/activestorage_attached.rb
152
+ - lib/rails_com/active_storage/attached_macros.rb
153
+ - lib/rails_com/active_storage/attachment_transfer.rb
154
+ - lib/rails_com/active_storage/blob_ext.rb
155
+ - lib/rails_com/active_storage/video_response.rb
116
156
  - lib/rails_com/config.rb
117
- - lib/rails_com/core_ext/array.rb
118
- - lib/rails_com/core_ext/date.rb
119
- - lib/rails_com/core_ext/hash.rb
120
- - lib/rails_com/core_ext/nil.rb
121
- - lib/rails_com/core_ext/numeric.rb
122
- - lib/rails_com/core_ext/string.rb
157
+ - lib/rails_com/core.rb
158
+ - lib/rails_com/core/array.rb
159
+ - lib/rails_com/core/date.rb
160
+ - lib/rails_com/core/hash.rb
161
+ - lib/rails_com/core/nil.rb
162
+ - lib/rails_com/core/numeric.rb
163
+ - lib/rails_com/core/string.rb
123
164
  - lib/rails_com/engine.rb
124
- - lib/rails_com/helpers/controller_helper.rb
125
- - lib/rails_com/helpers/model_helper.rb
165
+ - lib/rails_com/generators/named_base.rb
166
+ - lib/rails_com/generators/scaffold_generator.rb
126
167
  - lib/rails_com/meta/controllers.rb
127
168
  - lib/rails_com/meta/models.rb
128
169
  - lib/rails_com/meta/routes.rb
129
- - lib/rails_com/rails_ext/activestorage_attached.rb
130
- - lib/rails_com/rails_ext/attached_macros.rb
131
- - lib/rails_com/rails_ext/attachment_transfer.rb
132
- - lib/rails_com/rails_ext/errors.rb
133
- - lib/rails_com/rails_ext/named_base.rb
134
- - lib/rails_com/rails_ext/persistence_sneakily.rb
135
- - lib/rails_com/rails_ext/scaffold_generator.rb
136
- - lib/rails_com/rails_ext/template_renderer.rb
137
- - lib/rails_com/rails_ext/translation_helper.rb
138
- - lib/rails_com/rails_ext/video_response.rb
139
170
  - lib/rails_com/sprockets/non_digest_assets.rb
140
171
  - lib/rails_com/utils/babel.rb
141
172
  - lib/rails_com/utils/ip_helper.rb
@@ -146,15 +177,15 @@ files:
146
177
  - lib/rails_com/utils/uid_helper.rb
147
178
  - lib/rails_com/version.rb
148
179
  - lib/tasks/rails_com_tasks.rake
180
+ - lib/templates/erb/scaffold/_filter.html.erb.tt
149
181
  - lib/templates/erb/scaffold/_form.html.erb.tt
150
- - lib/templates/erb/scaffold/_search_form.html.erb.tt
151
182
  - lib/templates/erb/scaffold/edit.html.erb.tt
152
183
  - lib/templates/erb/scaffold/index.html.erb.tt
153
184
  - lib/templates/erb/scaffold/new.html.erb.tt
154
185
  - lib/templates/erb/scaffold/show.html.erb.tt
155
186
  - lib/templates/rails/scaffold_controller/api_controller.rb.tt
156
187
  - lib/templates/rails/scaffold_controller/controller.rb.tt
157
- homepage: https://github.com/yougexiangfa/rails_com
188
+ homepage: https://github.com/work-design/rails_com
158
189
  licenses:
159
190
  - LGPL-3.0
160
191
  metadata: {}
@@ -1,28 +0,0 @@
1
- <div class="top attached inline fields" id="<%= "#{target.record.class.name.underscore}_attachments_#{target.record.id}" %>">
2
- <div class="six wide field"></div>
3
- <div class="field ui tiny images" id="file_preview" data-controller="picture">
4
- <% if target.is_a?(ActiveStorage::Attached::One) && target.attached? %>
5
- <% if target.content_type.to_s.start_with?('image') %>
6
- <%= render partial: 'active_storage_ext/attachments/image_item', locals: { image: target } %>
7
- <% else %>
8
- <p id="attachment_<%= target.id %>">
9
- <%= link_to target.filename, rails_blob_path(target) %>
10
- <%= link_to 'x', rails_ext_attachment_path(target.id), method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>
11
- </p>
12
- <% end %>
13
- <% elsif target.is_a?(ActiveStorage::Attached::Many) && target.attached? %>
14
- <% target.each do |file| %>
15
- <% if file.content_type.to_s.start_with?('image') %>
16
- <%= render partial: 'active_storage_ext/attachments/image_item', locals: { image: file } %>
17
- <% else %>
18
- <p id="attachment_<%= file.id %>">
19
- <%= link_to file.filename, rails_blob_path(file) %>
20
- <%= link_to 'x', rails_ext_attachment_path(file.id), method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>
21
- </p>
22
- <% end %>
23
- <% end %>
24
- <% else %>
25
- <%= render partial: 'active_storage_ext/attachments/default_image_item' %>
26
- <% end %>
27
- </div>
28
- </div>
@@ -1,21 +0,0 @@
1
- module RailsExt
2
- module AttachedOne
3
-
4
- def attachment
5
-
6
- if super
7
- super
8
- elsif @blob_default ||= ActiveStorage::BlobDefault.find_by(record_class: record.class.name, name: name)
9
- @attachment ||= build_attachment(blob: @blob_default.file_blob)
10
- end
11
-
12
- end
13
-
14
- def attached?
15
- attachment&.id?
16
- end
17
-
18
- end
19
- end
20
-
21
-