rails_com 1.0.0 → 1.1.0

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/rails_com_manifest.js +3 -2
  3. data/app/assets/images/verification.jpg +0 -0
  4. data/app/assets/javascripts/rails_com/application.js +3 -0
  5. data/app/assets/stylesheets/rails_com/application.css +4 -0
  6. data/app/controllers/concerns/the_common_api.rb +20 -0
  7. data/app/controllers/the_guards_controller.rb +18 -0
  8. data/app/helpers/rails_com/active_helper.rb +18 -37
  9. data/app/helpers/rails_com_helper.rb +16 -0
  10. data/app/models/state_machine.rb +1 -1
  11. data/app/views/kaminari/_paginator.html.erb +1 -1
  12. data/app/views/layouts/rails_com/application.html.erb +17 -0
  13. data/app/views/the_guards/index.html.erb +18 -0
  14. data/config/locales/en.yml +7 -1
  15. data/config/routes.rb +3 -0
  16. data/lib/assets/javascripts/input-attachment.js +481 -0
  17. data/lib/assets/stylesheets/semantic.css +19466 -0
  18. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot +0 -0
  19. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf +0 -0
  20. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg +2671 -0
  21. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf +0 -0
  22. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff +0 -0
  23. data/lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2 +0 -0
  24. data/lib/nondigest_assets/images/themes/default/assets/images/flags.png +0 -0
  25. data/lib/rails_com/controller_helper.rb +25 -0
  26. data/lib/rails_com/core_ext/hash.rb +1 -0
  27. data/lib/rails_com/core_ext/nil.rb +7 -0
  28. data/lib/rails_com/engine.rb +8 -0
  29. data/lib/rails_com/helpers/qiniu_helper.rb +21 -50
  30. data/lib/rails_com/sprockets/non_digest_assets.rb +34 -0
  31. data/lib/rails_com/sprockets/qiniu_exporter.rb +21 -0
  32. data/lib/rails_com/sprockets.rb +15 -0
  33. data/lib/rails_com/version.rb +1 -1
  34. data/lib/rails_com.rb +6 -4
  35. data/lib/templates/erb/scaffold/_form.html.erb +19 -0
  36. data/lib/templates/erb/scaffold/edit.html.erb +2 -0
  37. data/lib/templates/erb/scaffold/index.html.erb +36 -0
  38. data/lib/templates/erb/scaffold/new.html.erb +1 -0
  39. data/lib/templates/erb/scaffold/show.html.erb +13 -0
  40. data/lib/templates/rails/scaffold_controller/controller.rb +47 -0
  41. metadata +45 -7
  42. data/app/assets/config/qiniu.js +0 -23
  43. data/app/assets/config/qiniu1.js +0 -25
@@ -0,0 +1,25 @@
1
+ module RailsCom::ControllerHelper
2
+
3
+ def inc_ip_count
4
+ Rails.cache.write "access/#{request.remote_ip}", ip_count + 1, expires_in: 60.seconds
5
+ end
6
+
7
+ def clear_ip_count
8
+ Rails.cache.write "access/#{request.remote_ip}", 0, expires_in: 60.seconds
9
+ end
10
+
11
+ def ip_count
12
+ Rails.cache.read("access/#{request.remote_ip}").to_i
13
+ end
14
+
15
+ def require_recaptcha
16
+ inc_ip_count
17
+ if ip_count >= 100
18
+ session[:back_to] = request.fullpath
19
+ redirect_to '/the_guards'
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ ActionController::Base.include RailsCom::ControllerHelper
@@ -34,4 +34,5 @@ class Hash
34
34
  yield(object)
35
35
  end
36
36
  end
37
+
37
38
  end
@@ -0,0 +1,7 @@
1
+ class NilClass
2
+
3
+ def to_d
4
+ to_s.to_d
5
+ end
6
+
7
+ end
@@ -5,5 +5,13 @@ module RailsCom
5
5
  app.config.assets.precompile += ['rails_com_manifest.js']
6
6
  end
7
7
 
8
+ initializer 'rails_com.add_generator_templates' do |app|
9
+ app.config.paths['lib/templates'].push File.expand_path('lib/templates', root)
10
+ end
11
+
12
+ initializer 'rails_com.add_assets_templates' do |app|
13
+ app.config.assets.paths.push *Dir[File.expand_path('lib/nondigest_assets/*', root)]
14
+ end
15
+
8
16
  end
9
17
  end
@@ -10,20 +10,35 @@ module QiniuHelper
10
10
  config['host'] + key.to_s
11
11
  end
12
12
 
13
- def generate_uptoken(key = nil)
13
+ def generate_uptoken(key = nil, **options)
14
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
15
18
  @uptoken = Qiniu::Auth.generate_uptoken(put_policy)
16
19
  end
17
20
 
18
- def upload(local_file, key = nil)
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)
19
27
  code, result, response_headers = Qiniu::Storage.upload_with_token_2(
20
- generate_uptoken(key),
28
+ generate_uptoken(key, options),
21
29
  local_file,
22
30
  key,
23
31
  nil,
24
32
  bucket: config['bucket']
25
33
  )
26
- result['key']
34
+ end
35
+
36
+ def delete(key)
37
+ code, result, response_headers = Qiniu::Storage.delete(
38
+ config['bucket'],
39
+ key
40
+ )
41
+ code
27
42
  end
28
43
 
29
44
  def list(prefix = '')
@@ -32,53 +47,9 @@ module QiniuHelper
32
47
  result['items']
33
48
  end
34
49
 
35
- def bsearch_last
36
- ary = (0..9).to_a.reverse
37
- search = 'chem_0'
38
- begin_index = 0
39
- end_index = ary.length - 1
40
- result = nil
41
-
42
- while true do
43
- if end_index - begin_index > 1
44
- index = ((begin_index + end_index) / 2.0).floor
45
- end_flag = false
46
- else
47
- index = end_index
48
- end_flag = true
49
- end
50
-
51
- search.sub! /\d$/, ary[index].to_s
52
- list = self.list(search)
53
-
54
- puts 'index: ' + index.to_s
55
- puts 'search: ' + search
56
- puts 'count: ' + list.size.to_s
57
- puts '-------------'
58
-
59
- if list.blank?
60
- begin_index = index
61
- elsif list.size >= 1
62
- end_index = index
63
-
64
- if end_flag
65
- search << '9'
66
- begin_index = 0
67
- end_index = ary.length - 1
68
-
69
- if list.size == 1
70
- break result = list[0]['key']
71
- end
72
- end
73
- end
74
- end
75
-
76
- result
77
- end
78
-
79
- def last
50
+ def last(prefix = '')
80
51
  ary = (0..9).to_a.reverse
81
- search = 'chem_0'
52
+ search = prefix
82
53
  result = nil
83
54
 
84
55
  while true do
@@ -0,0 +1,34 @@
1
+ require 'sprockets/manifest'
2
+
3
+ module NonDigestAssets
4
+
5
+ def compile(*args)
6
+ super
7
+
8
+ environment.paths.find_all { |i| i.include? 'nondigest_assets' }.each do |src|
9
+ r_src = src.to_s + '/.'
10
+ FileUtils.cp_r r_src, self.dir, verbose: true
11
+
12
+ if Sprockets.config[:sync].to_s == 'qiniu'
13
+ f_src = src.to_s + '/**/*'
14
+ path_src = Pathname.new src
15
+ Dir.glob(f_src).select { |f| File.file?(f) }.each do |file|
16
+ key = Pathname.new(file).relative_path_from(path_src)
17
+ QiniuHelper.upload file, 'assets/' + key.to_s
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def remove(filename)
24
+ super
25
+
26
+ if Sprockets.config[:sync].to_s == 'qiniu'
27
+ QiniuHelper.delete 'assets/' + filename.to_s
28
+ logger.info "--> Removed from Qiniu: #{ filename }"
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ Sprockets::Manifest.send(:prepend, NonDigestAssets)
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,15 @@
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,3 +1,3 @@
1
1
  module RailsCom
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/rails_com.rb CHANGED
@@ -1,14 +1,16 @@
1
- require 'rails_com/engine'
1
+ require 'rails_com/version'
2
+
2
3
  require 'rails_com/routes'
3
4
  require 'rails_com/models'
4
5
  require 'rails_com/model_helper'
6
+ require 'rails_com/controller_helper'
7
+ require 'rails_com/sprockets'
5
8
 
6
9
  require 'rails_com/helpers/uid_helper'
7
10
  require 'rails_com/helpers/jobber'
8
11
  require 'rails_com/helpers/qiniu_helper'
9
12
 
10
13
  require 'rails_com/core_ext/hash'
14
+ require 'rails_com/core_ext/nil'
11
15
 
12
- module RailsCom
13
- # Your code goes here...
14
- end
16
+ require 'rails_com/engine'
@@ -0,0 +1,19 @@
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 %>
@@ -0,0 +1,2 @@
1
+ <%%= render 'form' %>
2
+
@@ -0,0 +1,36 @@
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>
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,13 @@
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>
@@ -0,0 +1,47 @@
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
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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - qinmingyuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-10 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.1
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.1
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rucaptcha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Description of RailsCom.
28
42
  email:
29
43
  - mingyuan0715@foxmail.com
@@ -34,10 +48,12 @@ files:
34
48
  - MIT-LICENSE
35
49
  - README.md
36
50
  - Rakefile
37
- - app/assets/config/qiniu.js
38
- - app/assets/config/qiniu1.js
39
51
  - app/assets/config/rails_com_manifest.js
52
+ - app/assets/images/verification.jpg
40
53
  - app/assets/javascripts/rails_com/application.js
54
+ - app/assets/stylesheets/rails_com/application.css
55
+ - app/controllers/concerns/the_common_api.rb
56
+ - app/controllers/the_guards_controller.rb
41
57
  - app/helpers/rails_com/active_helper.rb
42
58
  - app/helpers/rails_com_helper.rb
43
59
  - app/models/state_machine.rb
@@ -48,16 +64,29 @@ files:
48
64
  - app/views/kaminari/_page.html.erb
49
65
  - app/views/kaminari/_paginator.html.erb
50
66
  - app/views/kaminari/_prev_page.html.erb
67
+ - app/views/layouts/rails_com/application.html.erb
51
68
  - app/views/shared/_alert.html.erb
52
69
  - app/views/shared/_error_messages.html.erb
70
+ - app/views/the_guards/index.html.erb
53
71
  - config/locales/en.yml
54
72
  - config/locales/zh.yml
55
73
  - config/routes.rb
74
+ - lib/assets/javascripts/input-attachment.js
75
+ - lib/assets/stylesheets/semantic.css
56
76
  - lib/generators/doc_model_generator.rb
57
77
  - lib/generators/doc_models_generator.rb
58
78
  - lib/generators/templates/model.erb
79
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.eot
80
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.otf
81
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.svg
82
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.ttf
83
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff
84
+ - lib/nondigest_assets/fonts/themes/default/assets/fonts/icons.woff2
85
+ - lib/nondigest_assets/images/themes/default/assets/images/flags.png
59
86
  - lib/rails_com.rb
87
+ - lib/rails_com/controller_helper.rb
60
88
  - lib/rails_com/core_ext/hash.rb
89
+ - lib/rails_com/core_ext/nil.rb
61
90
  - lib/rails_com/engine.rb
62
91
  - lib/rails_com/helpers/jobber.rb
63
92
  - lib/rails_com/helpers/qiniu_helper.rb
@@ -65,8 +94,17 @@ files:
65
94
  - lib/rails_com/model_helper.rb
66
95
  - lib/rails_com/models.rb
67
96
  - lib/rails_com/routes.rb
97
+ - lib/rails_com/sprockets.rb
98
+ - lib/rails_com/sprockets/non_digest_assets.rb
99
+ - lib/rails_com/sprockets/qiniu_exporter.rb
68
100
  - lib/rails_com/version.rb
69
101
  - lib/tasks/rails_com_tasks.rake
102
+ - lib/templates/erb/scaffold/_form.html.erb
103
+ - lib/templates/erb/scaffold/edit.html.erb
104
+ - lib/templates/erb/scaffold/index.html.erb
105
+ - lib/templates/erb/scaffold/new.html.erb
106
+ - lib/templates/erb/scaffold/show.html.erb
107
+ - lib/templates/rails/scaffold_controller/controller.rb
70
108
  homepage: https://github.com/qinmingyuan/rails_com
71
109
  licenses:
72
110
  - MIT
@@ -87,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
125
  version: '0'
88
126
  requirements: []
89
127
  rubyforge_project:
90
- rubygems_version: 2.6.8
128
+ rubygems_version: 2.6.11
91
129
  signing_key:
92
130
  specification_version: 4
93
131
  summary: Summary of RailsCom.
@@ -1,23 +0,0 @@
1
- var uploader = Qiniu.uploader({
2
- runtimes: 'html5,html4',
3
- browse_button: 'avatar_image_key_button',
4
- uptoken_url: '/uptoken',
5
- unique_names: true,
6
- save_key: false,
7
- domain: '<%= Settings.qiniu.public.domain %>',
8
- get_new_uptoken: false,
9
- container: 'container',
10
- max_file_size: '100mb',
11
- max_retries: 3,
12
- dragdrop: true,
13
- drop_element: 'container',
14
- chunk_size: '4mb',
15
- auto_start: true,
16
- init: {
17
- 'FileUploaded': function(up, file, info) {
18
- var res = $.parseJSON(info);
19
- $('#avatar_image_key_id').val(res.key);
20
- },
21
- 'Error': function(up, err, errTip) {}
22
- }
23
- });
@@ -1,25 +0,0 @@
1
- var Qiniu1 = new QiniuJsSDK;
2
-
3
- var uploader1 = Qiniu1.uploader({
4
- runtimes: 'html5,html4',
5
- browse_button: 'certificate_image_key_button',
6
- uptoken_url: '/private_uptoken',
7
- unique_names: true,
8
- save_key: false,
9
- domain: '<%= Settings.qiniu.private.domain %>',
10
- get_new_uptoken: false,
11
- container: 'container',
12
- max_file_size: '100mb',
13
- max_retries: 3,
14
- dragdrop: true,
15
- drop_element: 'container',
16
- chunk_size: '4mb',
17
- auto_start: true,
18
- init: {
19
- 'FileUploaded': function(up, file, info) {
20
- var res = $.parseJSON(info);
21
- $('#certificate_image_key_id').val(res.key);
22
- },
23
- 'Error': function(up, err, errTip) {}
24
- }
25
- });