makeme 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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +15 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/makeme +36 -0
- data/lib/makeme/fill.rb +10 -0
- data/lib/makeme/fill_helpers.rb +38 -0
- data/lib/makeme/guess.rb +33 -0
- data/lib/makeme/version.rb +3 -0
- data/lib/makeme.rb +36 -0
- data/makeme.gemspec +23 -0
- data/templates/Gemfile.erb +7 -0
- data/templates/README.md.erb +20 -0
- data/templates/Rakefile.erb +11 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 906bfd7f169a73ba26c53d978aa797ccd2320dee
|
4
|
+
data.tar.gz: 5d040d08aa8dee521feda04002f1b3a840a8dea7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c73021461c3af0dc46858041edbb566c7d89e33791c3f5e2e54fd4908ac0ba3119fd66293f34cecfacca79277ecef8df2a6c62443008e46de569b3c861aba981
|
7
|
+
data.tar.gz: 1ec0e67422f15a0ab6306c6b27e89cb3027e38c621aa047669946f323da01cd3cbf60a16cc541d1e3e8e187bc32b76d3f7e12daccc7af3444aab272dc061060f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ben Eills
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Makeme
|
2
|
+
Create a new file by guessing contents from filename
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```shell
|
7
|
+
gem install makeme
|
8
|
+
makeme Gemfile
|
9
|
+
makeme Rakefile
|
10
|
+
makeme README.md
|
11
|
+
```
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/beneills/makeme.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "makeme"
|
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
|
data/bin/setup
ADDED
data/exe/makeme
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
require 'makeme'
|
6
|
+
|
7
|
+
def usage
|
8
|
+
'usage: makeme FILENAME'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_args(args)
|
12
|
+
if args.length == 1
|
13
|
+
{ :given_path => ARGV[0] }
|
14
|
+
else
|
15
|
+
STDERR.puts usage
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def main
|
21
|
+
args = parse_args(ARGV)
|
22
|
+
|
23
|
+
working_directory = Dir.pwd
|
24
|
+
|
25
|
+
absolute_file_path = if Pathname.new(args[:given_path]).absolute?
|
26
|
+
args[:given_path]
|
27
|
+
else
|
28
|
+
File.join working_directory, args[:given_path]
|
29
|
+
end
|
30
|
+
|
31
|
+
options = {}
|
32
|
+
|
33
|
+
Makeme::run(working_directory, absolute_file_path, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
main
|
data/lib/makeme/fill.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'makeme/fill_helpers'
|
2
|
+
|
3
|
+
module Fill
|
4
|
+
def self.fill(working_directory, absolute_file_path, guess_data, template_contents, options)
|
5
|
+
template = ERB.new template_contents, nil, "%"
|
6
|
+
fill_helpers = FillHelpers.new(working_directory, absolute_file_path, guess_data)
|
7
|
+
|
8
|
+
template.result(fill_helpers.get_binding)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Internal
|
2
|
+
def placeholder(text)
|
3
|
+
text.upcase
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class FillHelpers
|
8
|
+
def initialize(working_directory, absolute_file_path, guess_data)
|
9
|
+
@working_directory = working_directory
|
10
|
+
@absolute_file_path = absolute_file_path
|
11
|
+
@guess_data = guess_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_binding
|
15
|
+
binding
|
16
|
+
end
|
17
|
+
|
18
|
+
def parent_directory
|
19
|
+
parent = Pathname.new(@absolute_file_path).parent.basename
|
20
|
+
|
21
|
+
if parent
|
22
|
+
parent.to_s
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def heuristic_project
|
29
|
+
parent_directory
|
30
|
+
end
|
31
|
+
|
32
|
+
def heuristic_username
|
33
|
+
Etc.getlogin
|
34
|
+
end
|
35
|
+
|
36
|
+
def project; heuristic_project || Internal.placeholder("myproject"); end
|
37
|
+
def username; heuristic_username || Internal.placeholder("username"); end
|
38
|
+
end
|
data/lib/makeme/guess.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Guess
|
4
|
+
def self.guess(working_directory, absolute_file_path, options)
|
5
|
+
guesser = BasenameGuesser.new
|
6
|
+
|
7
|
+
guesser.guess(working_directory, absolute_file_path, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
class Guesser
|
11
|
+
def guess(working_directory, absolute_file_path, options)
|
12
|
+
raise 'not implemented'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class BasenameGuesser < Guesser
|
17
|
+
@@templates_directory = File.join(File.dirname(__FILE__), "../../templates/")
|
18
|
+
|
19
|
+
def guess(working_directory, absolute_file_path, options)
|
20
|
+
absolute_file_path
|
21
|
+
|
22
|
+
basename = Pathname.new(absolute_file_path).basename
|
23
|
+
candidate_filename = File.join @@templates_directory, "#{basename}.erb"
|
24
|
+
|
25
|
+
if File.file? candidate_filename
|
26
|
+
template_contents = File.read candidate_filename
|
27
|
+
[{ :gueser => BasenameGuesser }, template_contents]
|
28
|
+
else
|
29
|
+
[{}, nil]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/makeme.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require "makeme/fill"
|
4
|
+
require "makeme/guess"
|
5
|
+
require "makeme/version"
|
6
|
+
|
7
|
+
module Makeme
|
8
|
+
def self.run(working_directory, absolute_file_path, options)
|
9
|
+
# Check that the file doesn't already exist
|
10
|
+
! File.exist?(absolute_file_path) || founder('File already exists!')
|
11
|
+
|
12
|
+
# Test that the file is not a directory
|
13
|
+
! absolute_file_path.end_with?('/') || founder('File is a directory!')
|
14
|
+
|
15
|
+
# Guess which template is right, or nil
|
16
|
+
guess_data, template_contents = Guess::guess(working_directory, absolute_file_path, options)
|
17
|
+
! template_contents.nil? || founder('Couldn\'t guess a template for that file!')
|
18
|
+
|
19
|
+
# Fill in template
|
20
|
+
contents = Fill::fill(working_directory, absolute_file_path, guess_data, template_contents, options)
|
21
|
+
|
22
|
+
# Write to file
|
23
|
+
open(absolute_file_path, 'w') do |f|
|
24
|
+
f.write contents
|
25
|
+
end
|
26
|
+
|
27
|
+
# Print nice message and exit with success
|
28
|
+
puts "Created #{absolute_file_path}" unless options[:silent]
|
29
|
+
exit 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.founder(message)
|
33
|
+
STDERR.puts message
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
end
|
data/makeme.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'makeme/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "makeme"
|
8
|
+
spec.version = Makeme::VERSION
|
9
|
+
spec.authors = ["Ben Eills"]
|
10
|
+
spec.email = ["ben@beneills.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create a new file by guessing contents from filename.}
|
13
|
+
spec.homepage = "https://github.com/beneills/makeme"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables << "makeme"
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!-- See https://guides.github.com/features/mastering-markdown/ -->
|
2
|
+
|
3
|
+
# <%= project.capitalize %>
|
4
|
+
Short summary line.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```shell
|
9
|
+
gem install <%= project %>
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```shell
|
15
|
+
<%= project %> help
|
16
|
+
```
|
17
|
+
|
18
|
+
## Contributing
|
19
|
+
|
20
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<%= username %>/<%= project %>.
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makeme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Eills
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-16 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ben@beneills.com
|
58
|
+
executables:
|
59
|
+
- makeme
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- exe/makeme
|
72
|
+
- lib/makeme.rb
|
73
|
+
- lib/makeme/fill.rb
|
74
|
+
- lib/makeme/fill_helpers.rb
|
75
|
+
- lib/makeme/guess.rb
|
76
|
+
- lib/makeme/version.rb
|
77
|
+
- makeme.gemspec
|
78
|
+
- templates/Gemfile.erb
|
79
|
+
- templates/README.md.erb
|
80
|
+
- templates/Rakefile.erb
|
81
|
+
homepage: https://github.com/beneills/makeme
|
82
|
+
licenses: []
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.5.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Create a new file by guessing contents from filename.
|
104
|
+
test_files: []
|