tynn-generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fa6428ffb89d643e1b411c5ae6267e0f1fdbf11
4
+ data.tar.gz: 5f2bc3f5889619b7873caf13ba0a46350226681b
5
+ SHA512:
6
+ metadata.gz: 8c6bf8370aeb1370709988394bbdf29053db94a7b685f34c1f7689d71c13cd4e651a4cd8fa351125fdc77237c4b21a09616df1bd325a15314f6f4c19082393c7
7
+ data.tar.gz: b8292e226b96d75ff437cf3788b4b7a15ccd6a7ba1216aa7a4cab18f81ee58a8f834c5561240c8de48a49bd8661566eca14d2a7660e1e513e42864c779f83d49
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /tmp
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Francesco Rodríguez and contributors
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ tynn-generator
2
+ ==============
3
+
4
+ Tynn' application generator.
5
+
6
+ Usage
7
+ -----
8
+
9
+ ```
10
+ ~ $ tynn
11
+ Usage: tynn <dir> [options]
12
+
13
+ Options:
14
+
15
+ -h, --help output usage information
16
+
17
+ ~ $ tynn myapp
18
+ create : myapp
19
+ create : myapp/app.rb
20
+ create : myapp/config.ru
21
+ ```
22
+
23
+ Installation
24
+ ------------
25
+
26
+ ```
27
+ $ gem install tynn-generator
28
+ ```
data/app_generator.rb ADDED
@@ -0,0 +1,7 @@
1
+ class AppGenerator < Tynn::Generator
2
+ def setup
3
+ generate("app.rb", message: "Hello World!")
4
+
5
+ generate("config.ru")
6
+ end
7
+ end
data/bin/tynn ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "clap"
4
+ require "erb"
5
+ require "ostruct"
6
+
7
+ class Tynn
8
+ class CLI
9
+ def self.parse(args)
10
+ new.parse(args)
11
+ end
12
+
13
+ attr_reader :template_path
14
+
15
+ def initialize
16
+ @template_path = File.expand_path("..", __dir__)
17
+ end
18
+
19
+ def parse(args)
20
+ args = Clap.run(args, opts)
21
+
22
+ usage if args.empty?
23
+
24
+ require(app_generator)
25
+
26
+ generator = AppGenerator.new(template_path, args)
27
+ generator.setup
28
+ end
29
+
30
+ def opts
31
+ return {
32
+ "-h" => method(:usage),
33
+ "--help" => method(:usage)
34
+ }
35
+ end
36
+
37
+ def app_generator
38
+ return File.join(template_path, "app_generator")
39
+ end
40
+
41
+ USAGE = <<-EOS
42
+ Usage: tynn <dir> [options]
43
+
44
+ Options:
45
+
46
+ -h, --help output usage information
47
+ EOS
48
+
49
+ def usage
50
+ puts(USAGE); exit(0)
51
+ end
52
+ end
53
+
54
+ class Generator
55
+ attr_reader :base_dir, :app_name
56
+
57
+ def initialize(base_dir, args)
58
+ @base_dir = base_dir
59
+ @app_name = args.first
60
+ end
61
+
62
+ def setup
63
+ raise("#{ self.class }#setup not implemented")
64
+ end
65
+
66
+ def generate(path, vars = {})
67
+ output_path = File.join(app_name, path)
68
+
69
+ mkdir(File.dirname(output_path))
70
+
71
+ write(output_path, render(path, vars))
72
+ end
73
+
74
+ def mkdir(path)
75
+ unless Dir.exist?(path)
76
+ Dir.mkdir(path)
77
+
78
+ log(path)
79
+ end
80
+ end
81
+
82
+ def write(path, content)
83
+ File.write(path, content)
84
+
85
+ log(path)
86
+ end
87
+
88
+ def render(path, vars = {})
89
+ source = File.read(File.join(base_dir, "templates", path))
90
+ params = OpenStruct.new(vars).instance_eval { binding }
91
+
92
+ return ERB.new(source).result(params)
93
+ end
94
+
95
+ def log(str)
96
+ puts(" \033[36mcreate\033[0m : #{ str }")
97
+ end
98
+ end
99
+ end
100
+
101
+ Tynn::CLI.parse(ARGV)
data/templates/app.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "tynn"
2
+
3
+ Tynn.define do
4
+ root do
5
+ res.write("<%= message %>")
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require File.expand_path("app", __dir__)
2
+
3
+ run(Tynn)
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "tynn-generator"
3
+ s.version = "0.0.1"
4
+ s.summary = "Tynn' application generator"
5
+ s.description = s.summary
6
+ s.authors = ["Francesco Rodríguez"]
7
+ s.email = ["frodsan@protonmail.ch"]
8
+ s.homepage = "https://github.com/frodsan/tynn-generator"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.executables.push("tynn")
14
+
15
+ s.add_dependency "clap", "~> 1.0"
16
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tynn-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: Tynn' application generator
28
+ email:
29
+ - frodsan@protonmail.ch
30
+ executables:
31
+ - tynn
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - LICENSE
37
+ - README.md
38
+ - app_generator.rb
39
+ - bin/tynn
40
+ - templates/app.rb
41
+ - templates/config.ru
42
+ - tynn-generator.gemspec
43
+ homepage: https://github.com/frodsan/tynn-generator
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Tynn' application generator
67
+ test_files: []