weapon 0.0.0 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b27a3373dacfd8082f456a9123ab25ace9fad5f8
4
- data.tar.gz: 07e036556f9a0b58428e946f38884b3896a8ca4a
3
+ metadata.gz: adbdcd9c9ecfe8d01977856be7ea48e05f0ca00b
4
+ data.tar.gz: c17182d3df20f3bdb1a6b549ea1681ded2d5ec5b
5
5
  SHA512:
6
- metadata.gz: 0a04d0625b65962deeb0cbe0a9e4ae68a1a019a30874106826d22403903cf809d1ad0e8c9dd5484c7f8ce2b5bc22c092820ee7e64391d2e0ae7990800e6f95c5
7
- data.tar.gz: 77f01274b0f9add55b26be2cdb4ccadd33575f7609ba3a40d4b0402bbcadbd84242b79044af48307aa59cc9f8d0a9c8163bf01167b89084a12cf24f83a20df2c
6
+ metadata.gz: 1a80078533dbed3a4ec272ee1999a76704e566e9d17b11c80b7f1d78f0ac812217bbd44516e4872d0daebe17e560446541826c52032bf6ddedb8d008e39a0b43
7
+ data.tar.gz: 8d21f59c6273382c9ab1bd7ddb6a41ab3c9a6209306d4446cddfd56280ce44e8a1b2a6038234df7a4c5c44bef1394439660de3440f21e981b525301ec8c512cc
data/bin/weapon ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'choice'
4
+ require 'weapon'
5
+ require 'awesome_print'
6
+
7
+ Weapon.start ARGV
@@ -0,0 +1,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,68 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+
9
+ # GET <%= route_url %>
10
+ def index
11
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
+ end
13
+
14
+ # GET <%= route_url %>/1
15
+ def show
16
+ end
17
+
18
+ # GET <%= route_url %>/new
19
+ def new
20
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
21
+ end
22
+
23
+ # GET <%= route_url %>/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST <%= route_url %>
28
+ def create
29
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
+
31
+ if @<%= orm_instance.save %>
32
+ redirect_to @<%= singular_table_name %>, notice: <%= "t('action.created.successfully')" %>
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT <%= route_url %>/1
39
+ def update
40
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
+ redirect_to @<%= singular_table_name %>, notice: <%= "t('action.updated.successfully')" %>
42
+ else
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ # DELETE <%= route_url %>/1
48
+ def destroy
49
+ @<%= orm_instance.destroy %>
50
+ redirect_to <%= index_helper %>_url, notice: <%= "t('action.destroyed.successfully')" %>
51
+ end
52
+
53
+ private
54
+ # Use callbacks to share common setup or constraints between actions.
55
+ def set_<%= singular_table_name %>
56
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
57
+ end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+ def <%= "#{singular_table_name}_params" %>
61
+ <%- if attributes_names.empty? -%>
62
+ params[:<%= singular_table_name %>]
63
+ <%- else -%>
64
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
65
+ <%- end -%>
66
+ end
67
+ end
68
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ h1 = t('action.edit') + <%= class_name %>.model_name.human
2
+
3
+ == render 'form'
4
+
5
+ = link_to t('action.show'), @<%= singular_table_name %>
6
+ '|
7
+ = link_to t('action.back'), <%= index_helper %>_path
@@ -0,0 +1,63 @@
1
+ require 'rails/generators/resource_helpers'
2
+
3
+ module Rails
4
+ module Generators
5
+ class I18nScaffoldControllerGenerator < NamedBase # :nodoc:
6
+ include ResourceHelpers
7
+
8
+ check_class_collision suffix: "Controller"
9
+
10
+ class_option :helper, type: :boolean
11
+ class_option :orm, banner: "NAME", type: :string, required: true,
12
+ desc: "ORM to generate the controller for"
13
+ class_option :api, type: :boolean,
14
+ desc: "Generates API controller"
15
+
16
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
17
+
18
+ def update_i18n
19
+ data = YAML.load_file "config/locales/zh-CN.yml"
20
+ if not data.has_key?("zh-CN")
21
+ data["zh-CN"] = {}
22
+ end
23
+ if not data['zh-CN'].has_key?("activerecord")
24
+ data["zh-CN"]["activerecord"] = {"models" => {}, "attributes" => {file_name => {}}}
25
+ end
26
+ if not data["zh-CN"].has_key?("helpers")
27
+ data["zh-CN"]["helpers"] = {}
28
+ end
29
+
30
+ if not data["zh-CN"]["helpers"].has_key?("submit")
31
+ data["zh-CN"]["helpers"]["submit"] = {}
32
+ end
33
+ data["zh-CN"]["helpers"]["submit"][file_name] = {"create" => "创建", "update" => "更新"}
34
+
35
+ data["zh-CN"]["activerecord"]["models"][file_name] = file_name
36
+ data["zh-CN"]["activerecord"]["attributes"][file_name] = {}
37
+
38
+ attributes.each do |attr|
39
+ data["zh-CN"]["activerecord"]["attributes"][file_name][attr.name] = attr.name
40
+ end
41
+ data["zh-CN"]["activerecord"]["attributes"][file_name]['id'] = 'ID'
42
+ data["zh-CN"]["activerecord"]["attributes"][file_name]['created_at'] = '创建时间'
43
+ data["zh-CN"]["activerecord"]["attributes"][file_name]['updated_at'] = '更新时间'
44
+
45
+ data["zh-CN"]['action'] = {'back' => '返回', 'new' => '创建', 'show' => '查看', 'edit' => '编辑', 'delete' => '删除', 'confirm_delete' => '确认删除', 'created' => {'successfully' => '创建成功'}, 'updated' => {'successfully' => '更新成功'}, 'destroyed' => {'successfully' => '删除成功'}}
46
+
47
+ File.open("config/locales/zh-CN.yml", 'wb') { |f| YAML.dump(data, f) }
48
+ end
49
+
50
+ def create_controller_files
51
+ template_file = options.api? ? "api_controller.rb" : "controller.rb"
52
+ template template_file, File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
53
+ end
54
+
55
+ hook_for :template_engine, :test_framework, as: :scaffold
56
+
57
+ # Invoke the helper using the controller name (pluralized)
58
+ hook_for :helper, as: :scaffold do |invoked|
59
+ invoke invoked, [ controller_name ]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,23 @@
1
+ h1 = <%= class_name %>.model_name.human
2
+
3
+ table.table.table-striped
4
+ tr
5
+ <% attributes.each do |attribute| -%>
6
+ th = <%= class_name %>.human_attribute_name("<%= attribute.name %>")
7
+ <% end -%>
8
+ th
9
+ th
10
+ th
11
+
12
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
13
+ tr
14
+ <% attributes.each do |attribute| -%>
15
+ td = <%= singular_table_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ td = link_to t('action.show'), <%= singular_table_name %>
18
+ td = link_to t('action.edit'), edit_<%= singular_table_name %>_path(<%= singular_table_name %>)
19
+ td = link_to t('action.delete'), <%= singular_table_name %>, :confirm => t('action.confirm_delete'), :method => :delete
20
+
21
+ br
22
+
23
+ = link_to (t('action.new') + <%= class_name %>.model_name.human), new_<%= singular_table_name %>_path
@@ -0,0 +1,5 @@
1
+ h1 = t('action.new') + <%= class_name %>.model_name.human
2
+
3
+ == render 'form'
4
+
5
+ = link_to t('action.back'), <%= index_helper %>_path
@@ -0,0 +1,11 @@
1
+ p#notice = notice
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ p
5
+ strong = <%= class_name %>.human_attribute_name("<%= attribute.name %>") + ':'
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to t('action.edit'), edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
10
+ '|
11
+ = link_to t('action.back'), <%= index_helper %>_path
@@ -0,0 +1,8 @@
1
+ zh-CN:
2
+ action:
3
+ new: 新建
4
+ edit: 编辑
5
+ show: 查看
6
+ delete: 删除
7
+ back: 返回
8
+ confirm_delete: 确认删除
@@ -0,0 +1,59 @@
1
+ require 'exception_notification/rails'
2
+
3
+ # config/initializers/exception_notification.rb
4
+ require 'exception_notification/sidekiq'
5
+
6
+ # 自定义 notifier(slack)
7
+ module ExceptionNotifier
8
+ class SlackNotifier
9
+
10
+ attr_accessor :notifier
11
+
12
+ def initialize(options)
13
+ begin
14
+ webhook_url = options.fetch(:webhook_url)
15
+ @message_opts = options.fetch(:additional_parameters, {})
16
+ @notifier = Slack::Notifier.new webhook_url, options
17
+ rescue
18
+ @notifier = nil
19
+ end
20
+ end
21
+
22
+ def call(exception, options={})
23
+ message = [
24
+ "时间: #{ Time.now.to_s }",
25
+ "URL: #{ options[:env]["REQUEST_URI"] }",
26
+ "参数: #{ options[:env]["action_dispatch.request.parameters"] }",
27
+ "用户IP: #{ options[:env]["action_dispatch.remote_ip"] }",
28
+ "异常: #{ [exception.message, exception.backtrace].flatten.join("\n") }",
29
+ "==============================================="
30
+ ].join("\n\n")
31
+
32
+ @notifier.ping(message, @message_opts) if valid?
33
+ end
34
+
35
+ protected
36
+
37
+ def valid?
38
+ !@notifier.nil?
39
+ end
40
+ end
41
+ end
42
+
43
+ ExceptionNotification.configure do |config|
44
+ # Ignore additional exception types.
45
+ # ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and ActionController::RoutingError are already added.
46
+ # config.ignored_exceptions += %w{ActionView::TemplateError CustomError}
47
+
48
+ # Adds a condition to decide when an exception must be ignored or not.
49
+ # The ignore_if method can be invoked multiple times to add extra conditions.
50
+ config.ignore_if do |exception, options|
51
+ not Rails.env.production?
52
+ end
53
+
54
+ config.add_notifier :slack, {
55
+ :webhook_url => "slack_webhook_url",
56
+ :channel => "slack_channel",
57
+ }
58
+
59
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails-settings-ui'
2
+
3
+ #= Application-specific
4
+ #
5
+ # # You can specify a controller for RailsSettingsUi::ApplicationController to inherit from:
6
+ # RailsSettingsUi.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
7
+ #
8
+ # # Render RailsSettingsUi inside a custom layout (set to 'application' to use app layout, default is RailsSettingsUi's own layout)
9
+ # RailsSettingsUi::ApplicationController.layout 'admin'
10
+
11
+ RailsSettingsUi.setup do |config|
12
+ config.settings_class = "Setting" # Customize settings class name
13
+ config.parent_controller = 'ActionController::Base'
14
+ end
@@ -0,0 +1,17 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: settings
4
+ #
5
+ # id :integer not null, primary key
6
+ # var :string(255) not null
7
+ # value :text(65535)
8
+ # thing_id :integer
9
+ # thing_type :string(30)
10
+ # created_at :datetime
11
+ # updated_at :datetime
12
+ #
13
+
14
+ class Setting < RailsSettings::CachedSettings
15
+ defaults[:mobile_regex_format] = '^1[3|4|5|8][0-9]\\d{8}$'
16
+ defaults[:real_name_regex_format] = '^[\u4E00-\u9FA5]{2,4}$'
17
+ end
data/lib/weapon.rb CHANGED
@@ -1,5 +1,109 @@
1
- class Weapon
2
- def self.hi
3
- puts "Hello world!"
1
+ require 'thor'
2
+ require 'awesome_print'
3
+
4
+ class Weapon < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
4
9
  end
10
+
11
+ desc "makesure_in_git", "makesure all the files is in git version control"
12
+ def makesure_in_git
13
+ run "spring stop"
14
+ unless (run "git remote -v")
15
+ puts "this project should in version controll use git"
16
+ run "git init"
17
+ run "git add *"
18
+ run "git commit -a -m 'first commit'"
19
+ end
20
+ end
21
+
22
+ desc "setup_mina_deploy", "setup mina deploy"
23
+ def setup_mina_deploy
24
+ invoke :makesure_in_git
25
+ puts "setup mina deploy"
26
+ run "mina init"
27
+ username = ask("input your user name on deploy host:")
28
+ File.open('config/deploy.rb', 'a') { |f| f.write("\nset :user, '#{username}' ")}
29
+ domain = ask("input your deploy host, like example.com or 123.100.100.100:")
30
+ gsub_file "config/deploy.rb", "'foobar.com'", "'" + domain + "'"
31
+ directory = ask("input your deploy directory:")
32
+ directory = directory.gsub(/\/$/, "")
33
+ gsub_file "config/deploy.rb", "/var/www/foobar.com", directory
34
+
35
+ repository = ask("input your git remote url to pull from, like git@github.com:seaify/weapon.git ")
36
+ gsub_file "config/deploy.rb", "git://...", repository
37
+
38
+ setup_dir_command = 'ssh ' + username + '@' + domain + " -t 'mkdir -p " + directory + ';chown -R ' + username + ' ' + directory + "'"
39
+ run setup_dir_command
40
+
41
+ run 'mina setup'
42
+ run 'scp config/database.yml ' + username + '@' + domain + ':' + directory + '/shared/config/'
43
+ run 'mina deploy'
44
+ end
45
+
46
+ desc "setup_settings_ui", "setup settings ui"
47
+ def setup_settings_ui
48
+ invoke :makesure_in_git
49
+ #inject_into_file "Gemfile", "gem 'rails-settings-ui', '~> 0.3.0'\n gem 'rails-settings-cached', '0.4.1'\n", :before => /^end/
50
+ File.open("Gemfile", "a").write("\ngem 'rails-settings-ui', '~> 0.3.0'\n gem 'rails-settings-cached', '0.4.1'\n")
51
+ run "bundle"
52
+ run "rails g settings setting"
53
+ run "rails g rails_settings_ui:install"
54
+ run "rake db:migrate"
55
+ copy_file 'support/rails_settings_ui/rails_settings_ui.rb', 'config/initializers/rails_settings_ui.rb'
56
+ copy_file 'support/rails_settings_ui/setting.rb', 'app/models/setting.rb'
57
+ end
58
+
59
+ desc "custom_i18n", "custom i18n and use slim as template engine, use simple_form, currently write to zh-CN.yml"
60
+ def custom_i18n
61
+ invoke :makesure_in_git
62
+ puts "custom i18n"
63
+ File.open("Gemfile", "a").write("\ngem 'slim-rails'\ngem 'simple_form', '~> 3.1.0'")
64
+ run "bundle"
65
+
66
+ unless File.exist?('config/locales/zh-CN.yml')
67
+ copy_file 'support/custom_i18n/zh-CN.yml', 'config/locales/zh-CN.yml'
68
+ end
69
+
70
+ invoke :config_bootstrap
71
+ run "rails g simple_form:install --bootstrap"
72
+ copy_file 'support/custom_i18n/_form.html.slim', 'lib/templates/slim/scaffold/_form.html.slim'
73
+ copy_file 'support/custom_i18n/index.html.slim', 'lib/templates/slim/scaffold/index.html.slim'
74
+ copy_file 'support/custom_i18n/new.html.slim', 'lib/templates/slim/scaffold/new.html.slim'
75
+ copy_file 'support/custom_i18n/edit.html.slim', 'lib/templates/slim/scaffold/edit.html.slim'
76
+ copy_file 'support/custom_i18n/show.html.slim', 'lib/templates/slim/scaffold/show.html.slim'
77
+
78
+ copy_file 'support/custom_i18n/controller.rb', 'lib/templates/rails/i18n_scaffold_controller/controller.rb'
79
+ copy_file 'support/custom_i18n/i18n_scaffold_controller_generator.rb', 'lib/generators/rails/i18n_scaffold_controller/i18n_scaffold_controller_generator.rb'
80
+
81
+ inject_into_file 'config/application.rb', after: "# -- all .rb files in that directory are automatically loaded.\n" do <<-'RUBY'
82
+ config.generators.template_engine = :slim
83
+ config.generators.scaffold_controller = "i18n_scaffold_controller"
84
+ config.i18n.default_locale = "zh-CN"
85
+ RUBY
86
+ end
87
+ run "rails g simple_form:install --bootstrap"
88
+ end
89
+
90
+ desc "config_bootstrap", "config bootstrap, example, used for simmple_form"
91
+ def config_bootstrap
92
+ File.open("Gemfile", "a").write("\ngem 'bootstrap-sass'")
93
+ run "bundle"
94
+ #config bootstrap stylesheets
95
+ File.open('app/assets/javascripts/application.js', 'a') { |f| f.write("\n//= require bootstrap-sprockets")}
96
+ File.open('app/assets/stylesheets/application.scss', 'a') { |f| f.write("\n@import 'bootstrap-sprockets';\n@import 'bootstrap';") }
97
+ run "rm app/assets/stylesheets/application.css"
98
+ end
99
+
100
+ desc "push_to_github", "push to github"
101
+ def push_to_github
102
+ invoke :makesure_in_git
103
+ puts "pull to github"
104
+ run 'gem install hub'
105
+ run "hub create #{File.basename(Dir.getwd)}"
106
+ run "hub push -u origin master"
107
+ end
108
+
5
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weapon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck.lei
@@ -9,14 +9,69 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-07-15 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.14'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
13
55
  description: provide mina deploy, github setup, slack exception notify, i18n scaffold,
14
56
  rails-settings-ui, guard custom
15
57
  email: dilin.life@gmail.com
16
- executables: []
58
+ executables:
59
+ - weapon
17
60
  extensions: []
18
61
  extra_rdoc_files: []
19
62
  files:
63
+ - bin/weapon
64
+ - lib/support/custom_i18n/_form.html.slim
65
+ - lib/support/custom_i18n/controller.rb
66
+ - lib/support/custom_i18n/edit.html.slim
67
+ - lib/support/custom_i18n/i18n_scaffold_controller_generator.rb
68
+ - lib/support/custom_i18n/index.html.slim
69
+ - lib/support/custom_i18n/new.html.slim
70
+ - lib/support/custom_i18n/show.html.slim
71
+ - lib/support/custom_i18n/zh-CN.yml
72
+ - lib/support/exception_slack_notify/exception_notification.rb
73
+ - lib/support/rails_settings_ui/rails_settings_ui.rb
74
+ - lib/support/rails_settings_ui/setting.rb
20
75
  - lib/weapon.rb
21
76
  homepage: http://rubygems.org/gems/weapon
22
77
  licenses: