rails_com 1.2.4 → 1.2.5
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -17
- data/app/assets/images/image-square.png +0 -0
- data/app/assets/javascripts/rails_com/application.js +43 -1
- data/{lib/assets/javascripts/input-attachment.js → app/assets/javascripts/rails_com/attachment.js} +24 -150
- data/app/assets/javascripts/rails_com/picture.js +17 -0
- data/app/controllers/{active_storage → active_storage_ext/admin}/attachments_controller.rb +2 -2
- data/app/controllers/active_storage_ext/admin/base_controller.rb +4 -0
- data/app/controllers/active_storage_ext/admin/blob_defaults_controller.rb +54 -0
- data/app/controllers/active_storage_ext/admin/blobs_controller.rb +48 -0
- data/app/controllers/active_storage_ext/audios_controller.rb +24 -0
- data/app/controllers/concerns/rails_common_api.rb +50 -0
- data/app/controllers/concerns/rails_common_xhr.rb +15 -0
- data/app/helpers/rails_com/active_helper.rb +21 -9
- data/app/helpers/rails_com/assets_helper.rb +57 -23
- data/app/helpers/rails_com/format_helper.rb +2 -2
- data/app/helpers/rails_com/time_helper.rb +2 -1
- data/app/models/active_storage/blob_default.rb +5 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/{state_machine.rb → concerns/state_machine.rb} +0 -0
- data/app/views/{active_storage → active_storage_ext/admin}/attachments/destroy.js.erb +0 -0
- data/app/views/active_storage_ext/admin/blob_defaults/_form.html.erb +7 -0
- data/app/views/active_storage_ext/admin/blob_defaults/_search_form.html.erb +7 -0
- data/app/views/active_storage_ext/admin/blob_defaults/edit.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blob_defaults/index.html.erb +48 -0
- data/app/views/active_storage_ext/admin/blob_defaults/new.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blob_defaults/show.html.erb +10 -0
- data/app/views/active_storage_ext/admin/blobs/_search_form.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blobs/destroy.js.erb +1 -0
- data/app/views/active_storage_ext/admin/blobs/index.html.erb +51 -0
- data/app/views/active_storage_ext/admin/blobs/new.html.erb +13 -0
- data/app/views/active_storage_ext/admin/blobs/show.html.erb +10 -0
- data/app/views/active_storage_ext/attachments/_default_image_item.html.erb +6 -0
- data/app/views/active_storage_ext/attachments/_image_item.html.erb +6 -0
- data/app/views/{active_storage → active_storage_ext}/attachments/_list.html.erb +1 -4
- data/app/views/{active_storage → active_storage_ext}/attachments/_list_edit.html.erb +1 -1
- data/app/views/{active_storage → active_storage_ext}/attachments/_list_form.html.erb +8 -8
- data/app/views/{active_storage → active_storage_ext}/attachments/_video_item.html.erb +0 -0
- data/app/views/active_storage_ext/audios/show.html.erb +5 -0
- data/config/locales/en.yml +2 -1
- data/config/locales/zh.yml +2 -1
- data/config/routes.rb +13 -6
- data/db/migrate/20181012025833_rails_com_init.rb +13 -0
- data/lib/mina/sidekiq.rb +3 -1
- data/lib/rails_com.rb +3 -1
- data/lib/rails_com/config.rb +2 -1
- data/lib/rails_com/core_ext/array.rb +2 -2
- data/lib/rails_com/core_ext/date.rb +3 -2
- data/lib/rails_com/engine.rb +3 -5
- data/lib/rails_com/helpers/model_helper.rb +10 -8
- data/lib/rails_com/rails_ext/activestorage_attached.rb +1 -1
- data/lib/rails_com/rails_ext/attached_macros.rb +21 -0
- data/lib/rails_com/rails_ext/attachment_transfer.rb +3 -1
- data/lib/rails_com/rails_ext/errors.rb +4 -0
- data/lib/rails_com/rails_ext/template_renderer.rb +15 -0
- data/lib/rails_com/utils/babel.rb +38 -0
- data/lib/rails_com/utils/time_helper.rb +9 -4
- data/lib/rails_com/version.rb +2 -2
- data/lib/templates/erb/scaffold/edit.html.erb.tt +2 -2
- data/lib/templates/erb/scaffold/new.html.erb.tt +2 -2
- data/lib/templates/erb/scaffold/show.html.erb.tt +2 -2
- metadata +39 -14
- data/app/assets/javascripts/rails_com/common.js +0 -38
- data/app/controllers/concerns/the_common_api.rb +0 -41
- data/app/views/active_storage/attachments/_image_item.html.erb +0 -6
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="ui segment breadcrumb">
|
2
|
+
<%= link_to 'Back', rails_ext_blobs_path, class: 'section' %>
|
3
|
+
<div class="divider"> / </div>
|
4
|
+
<div class="active section">Add</div>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="ui segment">
|
8
|
+
<%= form_with model: @blob, url: rails_ext_blobs_path, local: true do |f| %>
|
9
|
+
<%= render 'shared/error_messages', target: @blob %>
|
10
|
+
<%= f.file_field :io %>
|
11
|
+
<%= f.submit %>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<div class="ui image">
|
2
|
+
<a href="javascript:void(0);" onclick="this.parentNode.remove()" class="ui grey right corner mini label">
|
3
|
+
<i class="times icon"></i>
|
4
|
+
</a>
|
5
|
+
<%= image_tag 'image-square.png', data: { target: 'picture.src' }, style: 'max-width: 100%' %>
|
6
|
+
</div>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<div class="ui image">
|
2
|
+
<%= link_to rails_ext_attachment_path(image.id), method: :delete, data: {confirm: 'Are you sure?'}, remote: true, class: 'ui grey right corner mini label' do %>
|
3
|
+
<i class="times icon"></i>
|
4
|
+
<% end %>
|
5
|
+
<%= image_tag image, id: "attachment_#{image.id}", data: { target: 'picture.src' }, style: 'max-width: 100%' %>
|
6
|
+
</div>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if target.is_a?(ActiveStorage::Attached::One) && target.
|
1
|
+
<% if target.is_a?(ActiveStorage::Attached::One) && target.attachment.present? %>
|
2
2
|
<% if target.content_type.to_s.start_with?('image') %>
|
3
3
|
<%= image_tag target, style: 'max-width: 100%', class: 'ui small image' %>
|
4
4
|
<% elsif target.content_type.to_s.start_with?('video') %>
|
@@ -23,6 +23,3 @@
|
|
23
23
|
<% end %>
|
24
24
|
<% end %>
|
25
25
|
<% end %>
|
26
|
-
|
27
|
-
|
28
|
-
|
@@ -1,28 +1,28 @@
|
|
1
1
|
<div class="top attached inline fields" id="<%= "#{target.record.class.name.underscore}_attachments_#{target.record.id}" %>">
|
2
2
|
<div class="six wide field"></div>
|
3
|
-
<div class="field" id="file_preview" data-controller="
|
3
|
+
<div class="field ui tiny images" id="file_preview" data-controller="picture">
|
4
4
|
<% if target.is_a?(ActiveStorage::Attached::One) && target.attached? %>
|
5
5
|
<% if target.content_type.to_s.start_with?('image') %>
|
6
|
-
<%= render partial: '
|
6
|
+
<%= render partial: 'active_storage_ext/attachments/image_item', locals: { image: target } %>
|
7
7
|
<% else %>
|
8
8
|
<p id="attachment_<%= target.id %>">
|
9
9
|
<%= link_to target.filename, rails_blob_path(target) %>
|
10
|
-
<%= link_to 'x',
|
10
|
+
<%= link_to 'x', rails_ext_attachment_path(target.id), method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>
|
11
11
|
</p>
|
12
12
|
<% end %>
|
13
|
-
<% elsif target.is_a?(ActiveStorage::Attached::Many) %>
|
13
|
+
<% elsif target.is_a?(ActiveStorage::Attached::Many) && target.attached? %>
|
14
14
|
<% target.each do |file| %>
|
15
15
|
<% if file.content_type.to_s.start_with?('image') %>
|
16
|
-
<%= render partial: '
|
16
|
+
<%= render partial: 'active_storage_ext/attachments/image_item', locals: { image: file } %>
|
17
17
|
<% else %>
|
18
18
|
<p id="attachment_<%= file.id %>">
|
19
19
|
<%= link_to file.filename, rails_blob_path(file) %>
|
20
|
-
<%= link_to 'x',
|
20
|
+
<%= link_to 'x', rails_ext_attachment_path(file.id), method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>
|
21
21
|
</p>
|
22
22
|
<% end %>
|
23
23
|
<% end %>
|
24
|
+
<% else %>
|
25
|
+
<%= render partial: 'active_storage_ext/attachments/default_image_item' %>
|
24
26
|
<% end %>
|
25
27
|
</div>
|
26
28
|
</div>
|
27
|
-
|
28
|
-
|
File without changes
|
data/config/locales/en.yml
CHANGED
data/config/locales/zh.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
zh:
|
2
|
+
site_name: Rails Application
|
2
3
|
controller:
|
3
4
|
show: 详情
|
4
5
|
edit: 编辑
|
@@ -28,4 +29,4 @@ zh:
|
|
28
29
|
one: "Displaying <b>1</b> %{entry_name}"
|
29
30
|
other: "Displaying <b>all %{count}</b> %{entry_name}"
|
30
31
|
more_pages:
|
31
|
-
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
32
|
+
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
data/config/routes.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
scope :rails,
|
4
|
-
resources :attachments, only: [:destroy]
|
5
|
-
end
|
6
|
-
|
7
|
-
scope :rails, as: 'rails', module: 'active_storage_ext' do
|
3
|
+
scope :rails, module: 'active_storage_ext', as: 'rails_ext' do
|
8
4
|
resources :videos, only: [:show] do
|
9
5
|
put :transfer, on: :member
|
10
6
|
end
|
7
|
+
resources :audios, only: [:show] do
|
8
|
+
put :transfer, on: :member
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
scope :rails, module: 'active_storage_ext/admin', as: 'rails_ext' do
|
13
|
+
resources :attachments, only: [:destroy]
|
14
|
+
resources :blobs, only: [:index, :new, :create, :destroy] do
|
15
|
+
get :unattached, on: :collection
|
16
|
+
end
|
17
|
+
resources :blob_defaults
|
11
18
|
end
|
12
19
|
|
13
|
-
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RailsComInit < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
|
4
|
+
create_table :active_storage_blob_defaults do |t|
|
5
|
+
t.string :record_class
|
6
|
+
t.string :name
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
change_column_null :active_storage_blobs, :checksum, true
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
data/lib/mina/sidekiq.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
|
2
|
+
#:nodoc:
|
1
3
|
set :sidekiq, -> { "#{fetch :bundle_prefix} sidekiq -d" }
|
2
4
|
set :sidekiqctl, -> { "#{fetch :bundle_prefix} sidekiqctl" }
|
3
5
|
set :sidekiq_config, -> { "#{fetch :current_path}/config/sidekiq.yml" }
|
@@ -62,4 +64,4 @@ namespace :sidekiq do
|
|
62
64
|
invoke :'sidekiq:start'
|
63
65
|
end
|
64
66
|
|
65
|
-
end
|
67
|
+
end
|
data/lib/rails_com.rb
CHANGED
@@ -28,10 +28,12 @@ require 'rails_com/rails_ext/persistence_sneakily'
|
|
28
28
|
require 'rails_com/rails_ext/translation_helper'
|
29
29
|
require 'rails_com/rails_ext/video_response'
|
30
30
|
require 'rails_com/rails_ext/attachment_transfer'
|
31
|
+
require 'rails_com/rails_ext/errors'
|
31
32
|
require 'rails_com/sprockets/non_digest_assets'
|
32
33
|
|
33
34
|
# Utils
|
34
35
|
require 'rails_com/utils/time_helper'
|
35
36
|
require 'rails_com/utils/num_helper'
|
36
37
|
require 'rails_com/utils/uid_helper'
|
37
|
-
require 'rails_com/utils/jobber'
|
38
|
+
require 'rails_com/utils/jobber'
|
39
|
+
require 'rails_com/utils/babel'
|
data/lib/rails_com/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'active_support/configurable'
|
2
2
|
|
3
|
-
module RailsCom
|
3
|
+
module RailsCom #:nodoc:
|
4
4
|
include ActiveSupport::Configurable
|
5
5
|
|
6
6
|
configure do |config|
|
@@ -8,6 +8,7 @@ module RailsCom
|
|
8
8
|
'rails/welcome'
|
9
9
|
]
|
10
10
|
config.app_class = 'ApplicationController'
|
11
|
+
config.admin_class = 'AdminController'
|
11
12
|
end
|
12
13
|
|
13
14
|
end
|
@@ -49,8 +49,8 @@ class Array
|
|
49
49
|
# [:b, 2]
|
50
50
|
# ]
|
51
51
|
# raw_data.to_combined_h
|
52
|
-
#
|
53
|
-
#
|
52
|
+
# #=> { a: [1, 2], b: 2 }
|
53
|
+
# todo nested array bug
|
54
54
|
def to_combined_h
|
55
55
|
hash = {}
|
56
56
|
self.each { |x, y| hash[x] = hash[x] ? Array(hash[x]) << y : y }
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Date
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# Chinese custom after date
|
4
|
+
# '2018-01-01'.to_date.after(2.month) => '2018-02-31'
|
5
|
+
# '2018-01-31'.to_date.after(1.month) => '2018-03-02'
|
5
6
|
def after(other)
|
6
7
|
if ActiveSupport::Duration === other
|
7
8
|
if other.parts.keys == [:months]
|
data/lib/rails_com/engine.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class RailsCom::Engine < ::Rails::Engine
|
1
|
+
class RailsCom::Engine < ::Rails::Engine #:nodoc:
|
2
2
|
|
3
3
|
config.generators do |g|
|
4
4
|
g.stylesheets false
|
@@ -13,17 +13,15 @@ class RailsCom::Engine < ::Rails::Engine
|
|
13
13
|
app.config.assets.precompile += ['rails_com_manifest.js']
|
14
14
|
end
|
15
15
|
|
16
|
-
initializer 'rails_com.add_generator_templates' do |app|
|
17
|
-
app.config.paths['lib/templates'].unshift File.expand_path('lib/templates', root)
|
18
|
-
end
|
19
|
-
|
20
16
|
initializer 'rails_com.add_assets_templates' do |app|
|
21
17
|
app.config.assets.paths.push(*Dir[File.expand_path('lib/nondigest_assets/*', root)])
|
22
18
|
end
|
23
19
|
|
24
20
|
initializer 'rails_com.add_activestorage' do |app|
|
21
|
+
require 'rails_com/rails_ext/attached_macros'
|
25
22
|
ActiveStorage::DiskController.include VideoResponse
|
26
23
|
ActiveStorage::Attachment.include AttachmentTransfer
|
24
|
+
ActiveStorage::Attached::One.prepend RailsExt::AttachedOne
|
27
25
|
end
|
28
26
|
|
29
27
|
end
|
@@ -15,14 +15,16 @@ module RailsCom::ModelHelper
|
|
15
15
|
|
16
16
|
def column_attributes
|
17
17
|
columns.map do |column|
|
18
|
-
|
19
|
-
column.name.to_sym,
|
20
|
-
column.
|
21
|
-
column.type,
|
22
|
-
column.sql_type,
|
23
|
-
column.null,
|
24
|
-
column.
|
25
|
-
|
18
|
+
{
|
19
|
+
name: column.name.to_sym,
|
20
|
+
name_i18n: human_attribute_name(column.name),
|
21
|
+
type: column.type,
|
22
|
+
sql_type: column.sql_type,
|
23
|
+
null: column.null,
|
24
|
+
default: column.default,
|
25
|
+
default_function: column.default_function,
|
26
|
+
comment: column.comment
|
27
|
+
}
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -0,0 +1,21 @@
|
|
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
|
+
|
@@ -33,7 +33,22 @@ module RailsExt
|
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
36
|
+
|
37
|
+
module Parameters
|
38
|
+
|
39
|
+
def require(key)
|
40
|
+
begin
|
41
|
+
super
|
42
|
+
ensure
|
43
|
+
@required_params ||= []
|
44
|
+
@required_params << key
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
36
50
|
end
|
37
51
|
|
38
52
|
ActionView::TemplateRenderer.prepend RailsExt::TemplateRenderer
|
39
53
|
ActionView::PartialRenderer.prepend RailsExt::PartialRenderer
|
54
|
+
ActionController::Parameters.prepend RailsExt::Parameters
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Babel
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def script_path
|
7
|
+
@app_path = File.expand_path('.', Dir.pwd)
|
8
|
+
node_modules_bin_path = ENV['WEBPACKER_NODE_MODULES_BIN_PATH'] || `yarn bin`.chomp
|
9
|
+
babel_config = File.join(@app_path, '.babelrc')
|
10
|
+
|
11
|
+
"#{node_modules_bin_path}/babel --config-file #{babel_config}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def context(file)
|
15
|
+
`#{script_path} #{file}`
|
16
|
+
end
|
17
|
+
|
18
|
+
def transform(code, options = {})
|
19
|
+
tmpfile = write_to_tempfile(code)
|
20
|
+
|
21
|
+
begin
|
22
|
+
r = context(tmpfile)
|
23
|
+
ensure
|
24
|
+
File.unlink(tmpfile)
|
25
|
+
end
|
26
|
+
|
27
|
+
r
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_to_tempfile(contents)
|
31
|
+
tmpfile = Tempfile.open(['babel', 'js'])
|
32
|
+
tmpfile.write(contents)
|
33
|
+
r = tmpfile.path
|
34
|
+
tmpfile.close
|
35
|
+
r
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
module TimeHelper
|
2
2
|
extend self
|
3
3
|
|
4
|
-
def exact_distance_time(from_time, to_time)
|
5
|
-
|
6
|
-
|
4
|
+
def exact_distance_time(from_time = 0, to_time)
|
5
|
+
if to_time.is_a?(Numeric)
|
6
|
+
from_time = Time.at(from_time)
|
7
|
+
to_time = Time.at(to_time)
|
8
|
+
else
|
9
|
+
from_time = from_time.to_datetime
|
10
|
+
to_time = to_time.to_datetime
|
11
|
+
end
|
7
12
|
|
8
13
|
return {} if from_time > to_time
|
9
14
|
|
@@ -55,4 +60,4 @@ module TimeHelper
|
|
55
60
|
seconds
|
56
61
|
end
|
57
62
|
|
58
|
-
end
|
63
|
+
end
|
data/lib/rails_com/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module RailsCom
|
2
|
-
VERSION = '1.2.
|
1
|
+
module RailsCom #:nodoc:
|
2
|
+
VERSION = '1.2.5'
|
3
3
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<div class="ui segment breadcrumb">
|
2
2
|
<%%= link_to 'Back', <%= index_helper %>_path, class: 'section' %>
|
3
|
-
<div class="divider"
|
3
|
+
<div class="divider">/</div>
|
4
4
|
<div class="active section">Edit</div>
|
5
5
|
</div>
|
6
6
|
|
7
7
|
<div class="ui segment">
|
8
8
|
<%%= render 'form' %>
|
9
|
-
</div>
|
9
|
+
</div>
|