rails_com 1.2.0 → 1.2.1

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/app/assets/javascripts/rails_com/checkbox.js +59 -0
  4. data/app/assets/javascripts/rails_com/common.js +5 -2
  5. data/app/assets/javascripts/rails_com/fetch_xhr_script.js +3 -37
  6. data/app/assets/javascripts/rails_com/sidebar.js +40 -0
  7. data/app/controllers/common_controller.rb +0 -8
  8. data/app/controllers/concerns/the_common_api.rb +2 -2
  9. data/app/helpers/rails_com/active_helper.rb +1 -0
  10. data/app/helpers/{rails_com_helper.rb → rails_com/assets_helper.rb} +2 -10
  11. data/app/helpers/rails_com/common_helper.rb +13 -0
  12. data/app/helpers/rails_com/time_helper.rb +22 -0
  13. data/app/models/state_machine.rb +63 -15
  14. data/app/views/shared/_locales.html.erb +1 -1
  15. data/config/locales/en.yml +7 -1
  16. data/config/locales/zh.datetime.yml +44 -0
  17. data/config/locales/zh.yml +9 -0
  18. data/config/routes.rb +0 -4
  19. data/lib/mina/puma.rb +3 -2
  20. data/lib/mina/whenever.rb +27 -0
  21. data/lib/rails_com/config.rb +11 -0
  22. data/lib/rails_com/core_ext/array.rb +54 -0
  23. data/lib/rails_com/model_helper.rb +55 -4
  24. data/lib/rails_com/rails_ext/activestorage_attached.rb +32 -0
  25. data/lib/rails_com/rails_ext/persistence_sneakily.rb +11 -0
  26. data/lib/rails_com/rails_ext/scaffold_generator.rb +1 -0
  27. data/lib/rails_com/rails_ext/template_renderer.rb +3 -3
  28. data/lib/rails_com/rails_ext/translation_helper.rb +18 -0
  29. data/lib/rails_com/routes.rb +5 -0
  30. data/lib/rails_com/setting.rb +34 -0
  31. data/lib/rails_com/version.rb +1 -1
  32. data/lib/rails_com.rb +7 -5
  33. data/lib/templates/erb/scaffold/_search_form.html.erb.tt +1 -1
  34. data/lib/templates/erb/scaffold/edit.html.erb.tt +7 -12
  35. data/lib/templates/erb/scaffold/index.html.erb.tt +32 -36
  36. data/lib/templates/erb/scaffold/new.html.erb.tt +8 -12
  37. data/lib/utils/ip_helper.rb +21 -0
  38. data/lib/utils/time_helper.rb +37 -0
  39. metadata +17 -12
  40. data/config/initializers/time_format.rb +0 -1
  41. data/lib/assets/javascripts/semantic.js +0 -11
  42. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot +0 -0
  43. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf +0 -0
  44. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg +0 -947
  45. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf +0 -0
  46. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff +0 -0
  47. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2 +0 -0
  48. data/lib/nondigest_assets/fonts/themes/default/assets/images/flags.png +0 -0
@@ -0,0 +1,32 @@
1
+ module ActiveStorage
2
+ class Attached
3
+
4
+ def url_sync(url, filename = 'tmp_file_' + self.record.id.to_s)
5
+ tmp_path = File.expand_path 'tmp/storage_migrate'
6
+ file_path = File.join tmp_path, filename.to_s
7
+
8
+ File.open(file_path, 'w+') do |file|
9
+ file.binmode
10
+ HTTParty.get(url, stream_body: true) do |fragment|
11
+ file.write fragment
12
+ end
13
+
14
+ file.rewind
15
+ self.attach io: file, filename: filename
16
+ end
17
+ end
18
+
19
+
20
+ class One
21
+
22
+ def variant(transformations)
23
+ if attachment.variable?
24
+ attachment.variant(transformations)
25
+ else
26
+ self
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module PersistenceSneakily
2
+
3
+ def save_sneakily!(*args, &block)
4
+ self.method(:create_or_update).super_method.call(*args, &block)
5
+ end
6
+
7
+ end
8
+
9
+ ActiveSupport.on_load :active_record do
10
+ include PersistenceSneakily
11
+ end
@@ -1,3 +1,4 @@
1
+ require 'rails/generators'
1
2
  require 'rails/generators/erb/scaffold/scaffold_generator'
2
3
 
3
4
  class Erb::Generators::ScaffoldGenerator
@@ -1,6 +1,6 @@
1
1
  module RailsExt
2
2
  module TemplateRenderer
3
-
3
+
4
4
  # record where the view rendered from, main project or which engine
5
5
  # used by view helper methods: js_load, css_load, js_ready
6
6
  def render_template(template, layout_name = nil, locals = nil)
@@ -11,7 +11,7 @@ module RailsExt
11
11
 
12
12
  engine = result.classify.safe_constantize
13
13
 
14
- @view.instance_variable_set(:@_rendered_from, engine.root) if engine
14
+ @view.instance_variable_set(:@_rendered_from, engine.root) if engine
15
15
 
16
16
  super
17
17
  end
@@ -19,4 +19,4 @@ module RailsExt
19
19
  end
20
20
  end
21
21
 
22
- ActionView::TemplateRenderer.prepend RailsExt::TemplateRenderer
22
+ ActionView::TemplateRenderer.prepend RailsExt::TemplateRenderer
@@ -0,0 +1,18 @@
1
+ module RailsCom
2
+ module TranslationHelper
3
+
4
+ def t(key, options = {})
5
+ options[:default] ||= default_keys(key)
6
+ super
7
+ end
8
+
9
+ def default_keys(key)
10
+ [
11
+ ['controller' + key].join('.').to_sym
12
+ ]
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+ ActionView::Base.include RailsCom::TranslationHelper
@@ -9,6 +9,11 @@ module RailsCom::Routes
9
9
  routes_wrapper.select { |i| i[:controller] == controller.to_s }.map { |i| i[:action] }.uniq
10
10
  end
11
11
 
12
+ def controllers
13
+ _controllers = routes_wrapper.map { |i| i[:controller] }.compact.uniq
14
+ _controllers - RailsCom.config.ignore_controllers
15
+ end
16
+
12
17
  def routes_wrapper
13
18
  return @routes_wrapper if @routes_wrapper.present?
14
19
 
@@ -0,0 +1,34 @@
1
+ class Setting < OpenStruct
2
+
3
+ def initialize(hash = {})
4
+ @table = {}
5
+ @hash_table = {}
6
+
7
+ hash.each do |k, v|
8
+ if v.is_a?(Hash)
9
+ @table[k.to_sym] = self.class.new(v)
10
+ elsif v.is_a?(Array)
11
+ @table[k.to_sym] = v.map { |h| h.is_a?(Hash) ? self.class.new(h) : h }
12
+ else
13
+ @table[k.to_sym] = v
14
+ end
15
+ @hash_table[k.to_sym] = v
16
+ new_ostruct_member(k)
17
+ end
18
+ end
19
+
20
+ def to_hash
21
+ @hash_table.with_indifferent_access
22
+ end
23
+
24
+ end
25
+
26
+ class Settings < Array
27
+
28
+ def initialize(data = [])
29
+ data.map do |h|
30
+ self << Setting.new(h)
31
+ end
32
+ end
33
+
34
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsCom
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/rails_com.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rails_com/version'
2
+ require 'rails_com/config'
2
3
 
3
4
  require 'rails_com/routes'
4
5
  require 'rails_com/models'
@@ -12,14 +13,15 @@ require 'rails_com/helpers/jobber'
12
13
 
13
14
  require 'rails_com/core_ext/hash'
14
15
  require 'rails_com/core_ext/nil'
16
+ require 'rails_com/core_ext/array'
15
17
 
16
18
  require 'rails_com/rails_ext/template_renderer'
17
19
  require 'rails_com/rails_ext/scaffold_generator'
20
+ require 'rails_com/rails_ext/activestorage_attached'
21
+ require 'rails_com/rails_ext/persistence_sneakily'
22
+ require 'rails_com/rails_ext/translation_helper'
18
23
 
19
- require 'rails_com/engine'
24
+ require 'utils/time_helper'
20
25
 
21
- module RailsCom
22
- mattr_accessor :not_found_logger
26
+ require 'rails_com/engine'
23
27
 
24
- self.not_found_logger = ActiveSupport::Logger.new('log/not_found.log')
25
- end
@@ -1,4 +1,4 @@
1
- <%%= search_form_with css: { wrapper_all: 'inline field', wrapper_input: 'field', wrapper_submit: 'field', submit: 'ui green button'} do |f| %>
1
+ <%%= search_form_with do |f| %>
2
2
  <div class="fields">
3
3
  <%%= f.submit 'Search' %>
4
4
  </div>
@@ -1,14 +1,9 @@
1
- <div>
2
-
3
- <div class="ui segment breadcrumb">
4
- <%%= link_to 'Back', <%= index_helper %>_path, class: 'section' %>
5
- <div class="divider"> / </div>
6
- <div class="active section">Edit</div>
7
- </div>
8
-
9
- <div class="ui segment">
10
- <%%= render 'form' %>
11
- </div>
12
-
1
+ <div class="ui segment breadcrumb">
2
+ <%%= link_to 'Back', <%= index_helper %>_path, class: 'section' %>
3
+ <div class="divider"> / </div>
4
+ <div class="active section">Edit</div>
13
5
  </div>
14
6
 
7
+ <div class="ui segment">
8
+ <%%= render 'form' %>
9
+ </div>
@@ -1,43 +1,39 @@
1
- <div>
2
-
3
- <div class="ui top attached menu borderless">
4
- <div class="header item"><%= plural_table_name.titleize %></div>
5
- </div>
6
-
7
- <div class="ui segment bottom attached">
8
- <%%= render 'search_form' %>
1
+ <div class="ui top attached borderless menu">
2
+ <div class="header item"><%= plural_table_name.titleize %></div>
3
+ <div class="right menu">
4
+ <div class="item">
5
+ <%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_table_name %>_path, class: 'ui teal button' %>
6
+ </div>
9
7
  </div>
8
+ </div>
10
9
 
11
- <div class="ui segment top attached">
12
- <%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_table_name %>_path, class: 'ui teal button' %>
13
- </div>
10
+ <div class="ui attached segment">
11
+ <%%= render 'search_form' %>
12
+ </div>
14
13
 
15
- <table class="ui bottom attached table">
16
- <thead>
14
+ <table class="ui bottom attached table">
15
+ <thead>
16
+ <tr>
17
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
18
+ <th><%= attribute.human_name %></th>
19
+ <% end -%>
20
+ </tr>
21
+ </thead>
22
+
23
+ <tbody>
24
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
17
25
  <tr>
18
- <% attributes.reject(&:password_digest?).each do |attribute| -%>
19
- <th><%= attribute.human_name %></th>
20
- <% end -%>
21
- </tr>
22
- </thead>
23
-
24
- <tbody>
25
- <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
26
- <tr>
27
26
  <% attributes.reject(&:password_digest?).each do |attribute| -%>
28
- <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
27
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
29
28
  <% end -%>
30
- <td>
31
- <%%= link_to 'Show', <%= singular_table_name %>_path(<%= singular_table_name %>), class: 'ui blue label' %>
32
- <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'ui pink label' %>
33
- <%%= link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>), method: :delete, data: { confirm: 'Are you sure?' }, class: 'ui red label' %>
34
- </td>
35
- </tr>
36
- <%% end %>
37
- </tbody>
38
- </table>
39
-
40
- <%%= paginate @<%= plural_table_name %> %>
41
- </div>
42
-
29
+ <td>
30
+ <%%= link_to 'Show', <%= singular_table_name %>_path(<%= singular_table_name %>), class: 'ui blue label' %>
31
+ <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'ui pink label' %>
32
+ <%%= link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>), method: :delete, data: { confirm: 'Are you sure?' }, class: 'ui red label' %>
33
+ </td>
34
+ </tr>
35
+ <%% end %>
36
+ </tbody>
37
+ </table>
43
38
 
39
+ <%%= paginate @<%= plural_table_name %> %>
@@ -1,13 +1,9 @@
1
- <div>
2
-
3
- <div class="ui segment breadcrumb">
4
- <%%= link_to 'Back', <%= index_helper %>_path, class: 'section' %>
5
- <div class="divider"> / </div>
6
- <div class="active section">Add</div>
7
- </div>
8
-
9
- <div class="ui segment">
10
- <%%= render 'form' %>
11
- </div>
12
-
1
+ <div class="ui segment breadcrumb">
2
+ <%%= link_to 'Back', <%= index_helper %>_path, class: 'section' %>
3
+ <div class="divider"> / </div>
4
+ <div class="active section">Add</div>
13
5
  </div>
6
+
7
+ <div class="ui segment">
8
+ <%%= render 'form' %>
9
+ </div>
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 亚洲最新ip地址
4
+ # http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
5
+ module IpHelper
6
+ extend self
7
+
8
+ def read(name)
9
+ IO.foreach(name) do |x|
10
+ if x.match? /apnic\|CN\|ipv4/
11
+ r = x.split('|').values_at(3, 4)
12
+ int_min = IPAddr.new(r[0]).to_i
13
+ int_max = min + r[1].to_i - 1
14
+ ip_max = IPAddr.new(max, Socket::AF_INET).to_s
15
+
16
+ [r[0], ip_max, int_min, int_max]
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,37 @@
1
+ module TimeHelper
2
+ extend self
3
+
4
+ def exact_distance_time(from_time, to_time)
5
+ from_time = from_time.to_datetime
6
+ to_time = to_time.to_datetime
7
+
8
+ return {} if from_time > to_time
9
+
10
+ years = to_time.year - from_time.year
11
+ months = to_time.month - from_time.month
12
+ days = to_time.mday - from_time.mday
13
+ day_seconds = to_time.seconds_since_midnight.to_i - from_time.seconds_since_midnight.to_i
14
+
15
+ if day_seconds < 0
16
+ days -= 1
17
+ day_seconds = 86400 + day_seconds
18
+ end
19
+
20
+ if days < 0
21
+ months -= 1
22
+ days = to_time.prev_month.end_of_month.mday + days
23
+ end
24
+
25
+ if months < 0
26
+ years -= 1
27
+ months = 12 + months
28
+ end
29
+
30
+ hours, minute_seconds = day_seconds.to_i.divmod(3600)
31
+ minutes, seconds = minute_seconds.divmod(60)
32
+
33
+ { year: years, month: months, day: days, hour: hours, minute: minutes, second: seconds }
34
+ end
35
+
36
+ end
37
+
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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - qinmingyuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,15 +51,19 @@ files:
51
51
  - app/assets/config/rails_com_manifest.js
52
52
  - app/assets/images/verification.jpg
53
53
  - app/assets/javascripts/rails_com/application.js
54
+ - app/assets/javascripts/rails_com/checkbox.js
54
55
  - app/assets/javascripts/rails_com/common.js
55
56
  - app/assets/javascripts/rails_com/fetch_xhr_script.js
56
57
  - app/assets/javascripts/rails_com/footer.js
58
+ - app/assets/javascripts/rails_com/sidebar.js
57
59
  - app/assets/stylesheets/rails_com/application.css
58
60
  - app/controllers/common_controller.rb
59
61
  - app/controllers/concerns/the_common_api.rb
60
62
  - app/controllers/the_guards_controller.rb
61
63
  - app/helpers/rails_com/active_helper.rb
62
- - app/helpers/rails_com_helper.rb
64
+ - app/helpers/rails_com/assets_helper.rb
65
+ - app/helpers/rails_com/common_helper.rb
66
+ - app/helpers/rails_com/time_helper.rb
63
67
  - app/models/state_machine.rb
64
68
  - app/views/kaminari/_first_page.html.erb
65
69
  - app/views/kaminari/_gap.html.erb
@@ -73,27 +77,22 @@ files:
73
77
  - app/views/shared/_error_messages.html.erb
74
78
  - app/views/shared/_locales.html.erb
75
79
  - app/views/the_guards/index.html.erb
76
- - config/initializers/time_format.rb
77
80
  - config/locales/en.yml
81
+ - config/locales/zh.datetime.yml
78
82
  - config/locales/zh.yml
79
83
  - config/routes.rb
80
84
  - lib/assets/javascripts/input-attachment.js
81
- - lib/assets/javascripts/semantic.js
82
85
  - lib/generators/doc_model_generator.rb
83
86
  - lib/generators/doc_models_generator.rb
84
87
  - lib/generators/templates/model.erb
85
88
  - lib/mina/puma.rb
86
89
  - lib/mina/sidekiq.rb
87
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot
88
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf
89
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg
90
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf
91
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff
92
- - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2
93
- - lib/nondigest_assets/fonts/themes/default/assets/images/flags.png
90
+ - lib/mina/whenever.rb
94
91
  - lib/rails_com.rb
92
+ - lib/rails_com/config.rb
95
93
  - lib/rails_com/controller_helper.rb
96
94
  - lib/rails_com/controllers.rb
95
+ - lib/rails_com/core_ext/array.rb
97
96
  - lib/rails_com/core_ext/hash.rb
98
97
  - lib/rails_com/core_ext/nil.rb
99
98
  - lib/rails_com/engine.rb
@@ -101,9 +100,13 @@ files:
101
100
  - lib/rails_com/helpers/uid_helper.rb
102
101
  - lib/rails_com/model_helper.rb
103
102
  - lib/rails_com/models.rb
103
+ - lib/rails_com/rails_ext/activestorage_attached.rb
104
+ - lib/rails_com/rails_ext/persistence_sneakily.rb
104
105
  - lib/rails_com/rails_ext/scaffold_generator.rb
105
106
  - lib/rails_com/rails_ext/template_renderer.rb
107
+ - lib/rails_com/rails_ext/translation_helper.rb
106
108
  - lib/rails_com/routes.rb
109
+ - lib/rails_com/setting.rb
107
110
  - lib/rails_com/sprockets/non_digest_assets.rb
108
111
  - lib/rails_com/version.rb
109
112
  - lib/tasks/rails_com_tasks.rake
@@ -114,6 +117,8 @@ files:
114
117
  - lib/templates/erb/scaffold/new.html.erb.tt
115
118
  - lib/templates/erb/scaffold/show.html.erb.tt
116
119
  - lib/templates/rails/scaffold_controller/controller.rb.tt
120
+ - lib/utils/ip_helper.rb
121
+ - lib/utils/time_helper.rb
117
122
  homepage: https://github.com/qinmingyuan/rails_com
118
123
  licenses:
119
124
  - MIT
@@ -1 +0,0 @@
1
- Time::DATE_FORMATS[:admin] = '%Y-%m-%d %H:%M:%S'