flg 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 663c87bc1f95f17f643121e0cbe88de798293a8e
4
+ data.tar.gz: '08ed9ca079f0d6e2b00448772a906881e13c8087'
5
+ SHA512:
6
+ metadata.gz: 196a0b77fc362b7b079309e1c22720a12d74130457c8b362f0a09d3ce97eb91fcfd721137faecb9f9e26cee185199ada3b889d119046548caf1ec5db3dbee3de
7
+ data.tar.gz: 8533051e075b20fcddc24f80f5b499d11e1b4b121dc565b165c4426882217e6f06d768bc61768fbe9efc22180642fc5ba03b95c74e079260fb1bd2c64ca578bd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flg.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Flg
2
+
3
+ 一个简单的生成器工具
4
+
5
+ ## File API
6
+ http://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html
7
+
8
+
9
+ ## Data handle
10
+
11
+ support active_support
12
+
13
+ ```ruby
14
+ 'active_record'.camelize # => "ActiveRecord"
15
+ 'active_record'.camelize(:lower) # => "activeRecord"
16
+ ```
17
+
18
+ ```ruby
19
+ 'ham_and_eggs'.classify # => "HamAndEgg"
20
+ 'posts'.classify # => "Post"
21
+ ```
22
+
23
+ ```ruby
24
+ 'employee_salary'.humanize # => "Employee salary"
25
+ 'author_id'.humanize # => "Author"
26
+ 'author_id'.humanize(capitalize: false) # => "author"
27
+ '_id'.humanize # => "Id"
28
+ ```
29
+
30
+ ```ruby
31
+ ActiveModel'.underscore # => "active_model"
32
+ 'ActiveModel::Errors'.underscore # => "active_model/errors"
33
+ ```
34
+
35
+ ```ruby
36
+ "13-12-2012".to_time # => 2012-12-13 00:00:00 +0100
37
+ "06:12".to_time # => 2012-12-13 06:12:00 +0100
38
+ "2012-12-13 06:12".to_time # => 2012-12-13 06:12:00 +0100
39
+ "2012-12-13T06:12".to_time # => 2012-12-13 06:12:00 +0100
40
+ "2012-12-13T06:12".to_time(:utc) # => 2012-12-13 06:12:00 UTC
41
+ "12/13/2012".to_time # => ArgumentError: argument out of range
42
+ ```
43
+
44
+ ```ruby
45
+ "1-1-2012".to_datetime # => Sun, 01 Jan 2012 00:00:00 +0000
46
+ "01/01/2012 23:59:59".to_datetime # => Sun, 01 Jan 2012 23:59:59 +0000
47
+ "2012-12-13 12:50".to_datetime # => Thu, 13 Dec 2012 12:50:00 +0000
48
+ "12/13/2012".to_datetime # => ArgumentError: invalid date
49
+ ```
50
+
51
+ ```ruby
52
+ "1-1-2012".to_date # => Sun, 01 Jan 2012
53
+ "01/01/2012".to_date # => Sun, 01 Jan 2012
54
+ "2012-12-13".to_date # => Thu, 13 Dec 2012
55
+ "12/13/2012".to_date # => ArgumentError: invalid date
56
+ ```
57
+
58
+ ```ruby
59
+ 'RawScaledScorer'.tableize # => "raw_scaled_scorers"
60
+ 'ham_and_egg'.tableize # => "ham_and_eggs"
61
+ 'fancyCategory'.tableize # => "fancy_categories"
62
+ ```
63
+
64
+ ```ruby
65
+ 'posts'.singularize # => "post"
66
+ 'octopi'.singularize # => "octopus"
67
+ 'sheep'.singularize # => "sheep"
68
+ 'word'.singularize # => "word"
69
+ 'the blue mailmen'.singularize # => "the blue mailman"
70
+ 'CamelOctopi'.singularize # => "CamelOctopus"
71
+ 'leyes'.singularize(:es) # => "ley"
72
+ ```
73
+
74
+ ```ruby
75
+ 'post'.pluralize # => "posts"
76
+ 'octopus'.pluralize # => "octopi"
77
+ 'sheep'.pluralize # => "sheep"
78
+ 'words'.pluralize # => "words"
79
+ 'the blue mailman'.pluralize # => "the blue mailmen"
80
+ 'CamelOctopus'.pluralize # => "CamelOctopi"
81
+ 'apple'.pluralize(1) # => "apple"
82
+ 'apple'.pluralize(2) # => "apples"
83
+ 'ley'.pluralize(:es) # => "leyes"
84
+ 'ley'.pluralize(1, :es) # => "ley"
85
+ ```
86
+
87
+ ```ruby
88
+
89
+ ```
90
+ ## Installation
91
+
92
+ Add this line to your application's Gemfile:
93
+
94
+ ```ruby
95
+ gem 'flg'
96
+ ```
97
+
98
+ And then execute:
99
+
100
+ $ bundle
101
+
102
+ Or install it yourself as:
103
+
104
+ $ gem install flg
105
+
106
+ ## Usage
107
+
108
+ TODO: Write usage instructions here
109
+
110
+ ## Development
111
+
112
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
113
+
114
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
115
+
116
+ ## Contributing
117
+
118
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mj/flg.
119
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/flg ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'flg'
3
+ require 'gli'
4
+ require 'fileutils'
5
+
6
+ include FileUtils
7
+ include GLI::App
8
+ include Flg::Shell
9
+ include Flg::Template
10
+
11
+ _source = open('./generators/flg').read
12
+ eval(_source)
13
+
14
+ exit run(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/flg.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flg"
8
+ spec.version = Flg::VERSION
9
+ spec.authors = ["mj"]
10
+ spec.email = ["tywf91@gmail.com"]
11
+
12
+ spec.summary = %q{simple custom generator}
13
+ spec.description = %q{simple custom generator}
14
+ spec.homepage = "http://www.oxo.ooo"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = ["flg"]
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "tty"
26
+ spec.add_dependency "activesupport"
27
+ spec.add_dependency "gli"
28
+ end
data/generators/flg ADDED
@@ -0,0 +1,31 @@
1
+ program_desc '命令行描述'
2
+
3
+ desc '简短说明'
4
+ long_desc '长说明'
5
+ command :add do |c|
6
+ c.action do |global, options, args|
7
+ puts args
8
+ end
9
+ end
10
+
11
+ command :run do |c|
12
+ c.action do |global, options, args|
13
+ shell "bundle"
14
+ end
15
+ end
16
+
17
+ command :mkdir do |c|
18
+ c.action do |global, options, args|
19
+ mkdir_p "./demo"
20
+ end
21
+ end
22
+
23
+ command :t do |c|
24
+ c.action do |global, options, args|
25
+ render name: 'demo.js.erb',
26
+ data: {
27
+ class_name: args.first.camelize
28
+ },
29
+ path: './demo.js'
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ class <%= class_name %> extends React.Component {
4
+ constructor(props) {
5
+ super(props);
6
+ }
7
+
8
+ render() {
9
+ return (
10
+ <div></div>
11
+ );
12
+ }
13
+ }
data/lib/flg/shell.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+
4
+
5
+ module Flg
6
+ module Shell
7
+ def shell(str)
8
+ cmd = TTY::Command.new
9
+ cmd.run str
10
+ end
11
+
12
+ def file(path)
13
+ pathname = Pathname.new path
14
+ FileUtils.mkdir_p pathname.dirname.to_s
15
+ File.open(path, 'w+')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ module Flg
7
+ module Template
8
+ class ErbalT < OpenStruct
9
+ def self.render_from_hash(t, h)
10
+ ErbalT.new(h).render(t)
11
+ end
12
+
13
+ def render(template)
14
+ ERB.new(template).result(binding)
15
+ end
16
+ end
17
+
18
+ def render(name: nil, data: nil, path: nil)
19
+ template = File.read("./generators/templates/#{name}")
20
+ str = ErbalT::render_from_hash(template, data)
21
+ if File.exist?(path)
22
+ prompt = TTY::Prompt.new
23
+ if prompt.no?("#{path} replace?")
24
+ puts 'ignore: ' + path
25
+ save_file(path, str)
26
+ else
27
+ return
28
+ end
29
+ else
30
+ save_file(path, str)
31
+ puts 'created: ' + path
32
+ end
33
+ end
34
+
35
+ def save_file(path, str)
36
+ pathname = Pathname.new path
37
+ FileUtils.mkdir_p pathname.dirname.to_s
38
+ File.open(path, 'w+') do |f|
39
+ f.puts str
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Flg
2
+ VERSION = "0.1.0"
3
+ end
data/lib/flg.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "flg/version"
2
+ require "flg/shell"
3
+ require 'flg/template'
4
+ require 'active_support/all'
5
+ require 'tty'
6
+
7
+ module Flg
8
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gli
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: simple custom generator
84
+ email:
85
+ - tywf91@gmail.com
86
+ executables:
87
+ - flg
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/flg
97
+ - bin/setup
98
+ - flg.gemspec
99
+ - generators/flg
100
+ - generators/templates/demo.js.erb
101
+ - lib/flg.rb
102
+ - lib/flg/shell.rb
103
+ - lib/flg/template.rb
104
+ - lib/flg/version.rb
105
+ homepage: http://www.oxo.ooo
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.12
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: simple custom generator
128
+ test_files: []