cuba-template-generator 0.0.8
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 +16 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +8 -0
- data/bin/cuba +9 -0
- data/cuba-template-generator.gemspec +26 -0
- data/lib/cuba/generator/cli.rb +32 -0
- data/lib/cuba/generator/version.rb +5 -0
- data/lib/cuba/generator.rb +75 -0
- data/lib/cuba/templates/api.erb +24 -0
- data/lib/cuba/templates/app.erb +34 -0
- data/lib/cuba/templates/gemfile.erb +11 -0
- data/lib/cuba/templates/postgres.erb +22 -0
- data/lib/cuba/templates/rack_config.erb +7 -0
- data/spec/cuba_template_generator_spec.rb +20 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: facabc4ede4091ec83ad35640765fc6b5ceeda15
|
4
|
+
data.tar.gz: 10079bc95a44d424634a1b910a10cbac59ad2468
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69205e075495bd9aa40daf3719504ff36f424c1fdf84d75aec5d8f538d5df010837790fc9ab54b9a58ff749849d0a38a1803cfda49af7b8eac4bd74860da8f13
|
7
|
+
data.tar.gz: 0655da49c76ba0d180668c24343e45be8296c0181bb9b4cc059b6121370e9f9644aecdfef702e3300e37a8af179c9ba2e8407275c90510abf573808ec47f82c5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Derek Viera
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
# cuba-template-generator
|
3
|
+
|
4
|
+
cuba-template-generator is a generator to help creating Cuba projects.
|
5
|
+
|
6
|
+
[Cuba](https://github.com/soveran/cuba) is a micro-framework for Ruby based on Rack.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install cuba-template-generator
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
cuba new [projectName] [options]
|
15
|
+
|
16
|
+
Additionally you can specify the type of your app via ***--type*** . E.g to generate an API starting point.
|
17
|
+
|
18
|
+
cuba new [projectName] --type api
|
19
|
+
|
20
|
+
To generate an application with a Postgresql configuration setup use ***-database*** option (via Datamapper)
|
21
|
+
|
22
|
+
cuba new [projectName] --database postgresql
|
23
|
+
|
24
|
+
By default ***--type*** is 'app'.
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/rangeroob/cuba-template-generator/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
33
|
+
|
34
|
+
## Thanks
|
35
|
+
|
36
|
+
This project is inspired from [cuba-libre](https://github.com/gdurelle/cuba-libre).
|
37
|
+
|
38
|
+
This project is forked from [cuba-generator](https://github.com/sdogruyol/cuba-generator)
|
data/Rakefile
ADDED
data/bin/cuba
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cuba/generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cuba-template-generator'
|
8
|
+
spec.version = Cuba::Generator::VERSION
|
9
|
+
spec.authors = ['Derek Viera']
|
10
|
+
spec.email = ['ma.dmviera01@gmail.com']
|
11
|
+
spec.summary = %q{Application Generator for Cuba framework.}
|
12
|
+
spec.description = %q{Helps create cuba projects through a minimalist generator.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
24
|
+
spec.add_dependency 'cuba', '~> 3.4.0'
|
25
|
+
spec.add_runtime_dependency 'commander', '~> 4.3.0'
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require_relative 'version'
|
3
|
+
require_relative '../generator'
|
4
|
+
|
5
|
+
module Cuba
|
6
|
+
class Cli
|
7
|
+
include Commander::Methods
|
8
|
+
|
9
|
+
def run
|
10
|
+
program :name, 'cuba'
|
11
|
+
program :version, Cuba::Generator::VERSION
|
12
|
+
program :description, 'Application Generator for Cuba framework.'
|
13
|
+
|
14
|
+
command :new do |c|
|
15
|
+
c.syntax = 'cuba new [options]'
|
16
|
+
c.description = 'Creates a new Cuba app'
|
17
|
+
c.option '--type STRING', String, 'Creates an app with preferred type'
|
18
|
+
c.option '--database STRING', String, 'Setups a database configuration with DataMapper'
|
19
|
+
c.action do |args, options|
|
20
|
+
if options.type
|
21
|
+
generator = Cuba::Generator.new(ARGV[1], options.type)
|
22
|
+
generator.create_postgres_file if options.database == 'postgresql'
|
23
|
+
else
|
24
|
+
generator = Cuba::Generator.new(ARGV[1], :app)
|
25
|
+
generator.create_postgres_file if options.database == 'postgresql'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
run!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'cuba/generator/version'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'erb'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module Cuba
|
7
|
+
class Generator
|
8
|
+
APPROOT = File.expand_path(File.dirname(__FILE__))
|
9
|
+
|
10
|
+
def initialize(name, type)
|
11
|
+
@project_name = name.downcase
|
12
|
+
@type = type
|
13
|
+
create_dir
|
14
|
+
create_config_file
|
15
|
+
create_cuba_file
|
16
|
+
puts "Created your Cuba #{@type} at /#{@project_name} directory. Rock on!"
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_dir
|
20
|
+
Dir.mkdir(@project_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_config_file
|
24
|
+
File.open("./#{@project_name}/config.ru", 'w+') do |file|
|
25
|
+
file.write setup_config
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_cuba_file
|
30
|
+
File.open("./#{@project_name}/#{@project_name}.rb", 'w+') do |file|
|
31
|
+
file.write setup_cuba
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_postgres_file
|
36
|
+
File.open("./#{@project_name}/postgres.rb", 'w+') do |file|
|
37
|
+
file.write setup_postgres
|
38
|
+
end
|
39
|
+
File.open("./#{@project_name}/Gemfile", 'w+') do |file|
|
40
|
+
file.write setup_gemfile
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def setup_cuba
|
47
|
+
if @type.to_sym == :app
|
48
|
+
create_template 'app'
|
49
|
+
elsif @type.to_sym == :api
|
50
|
+
create_template 'api'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def setup_config
|
55
|
+
create_template 'rack_config'
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_postgres
|
59
|
+
create_template 'postgres'
|
60
|
+
end
|
61
|
+
|
62
|
+
def setup_gemfile
|
63
|
+
create_template 'gemfile'
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_template(name)
|
67
|
+
template = File.read File.join(APPROOT, 'templates/', "#{name}.erb")
|
68
|
+
erb(template, {project_name: @project_name})
|
69
|
+
end
|
70
|
+
|
71
|
+
def erb(template, vars)
|
72
|
+
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%=
|
2
|
+
<<-TEMPLATE
|
3
|
+
require 'cuba'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# If you need extra protection.
|
7
|
+
# require 'rack/protection'
|
8
|
+
# Cuba.use Rack::Protection
|
9
|
+
# Cuba.use Rack::Protection::RemoteReferrer
|
10
|
+
|
11
|
+
# To launch just type: 'rackup' in your console
|
12
|
+
Cuba.define do
|
13
|
+
on get do
|
14
|
+
|
15
|
+
on root do
|
16
|
+
data = { first_name: 'Hello', last_name: 'World' }
|
17
|
+
res.headers["Content-Type"] = "application/json; charset=utf-8"
|
18
|
+
res.write data.to_json
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
TEMPLATE
|
24
|
+
%>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<%=
|
2
|
+
<<-TEMPLATE
|
3
|
+
require 'cuba'
|
4
|
+
|
5
|
+
Cuba.use Rack::Session::Cookie, :secret => "#{SecureRandom.base64(64)}"
|
6
|
+
|
7
|
+
# If you need extra protection.
|
8
|
+
# require 'rack/protection'
|
9
|
+
# Cuba.use Rack::Protection
|
10
|
+
# Cuba.use Rack::Protection::RemoteReferrer
|
11
|
+
|
12
|
+
# Cuba includes a plugin called Cuba::Render that provides a couple of helper methods for rendering templates.
|
13
|
+
# require "cuba/render"
|
14
|
+
# Cuba.plugin(Cuba::Render)
|
15
|
+
|
16
|
+
# This plugin uses Tilt, which serves as an interface to a bunch of different Ruby template engines
|
17
|
+
# (ERB, Haml, Sass, CoffeeScript, etc.), so you can use the template engine of your choice.
|
18
|
+
|
19
|
+
# require 'erb'
|
20
|
+
# Cuba.settings[:render][:template_engine] = "erb"
|
21
|
+
# Cuba.settings[:render][:views] = "./views"
|
22
|
+
|
23
|
+
# To launch just type: 'rackup' in your console
|
24
|
+
Cuba.define do
|
25
|
+
on get do
|
26
|
+
|
27
|
+
on root do
|
28
|
+
res.write "Hello #{project_name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
TEMPLATE
|
34
|
+
%>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%=
|
2
|
+
<<-TEMPLATE
|
3
|
+
|
4
|
+
require 'data_mapper'
|
5
|
+
|
6
|
+
DataMapper.setup(:default, 'postgres://username@localhost/db_name')
|
7
|
+
|
8
|
+
# Here's an example User model
|
9
|
+
# class User
|
10
|
+
# include DataMapper::Resource
|
11
|
+
#
|
12
|
+
# property :id, Serial # An auto-increment integer key
|
13
|
+
# property :email, String # A varchar type string, for short strings
|
14
|
+
# property :created_at, DateTime # A DateTime, for any date you might like.
|
15
|
+
# property :updated_at, DateTime
|
16
|
+
# end
|
17
|
+
|
18
|
+
DataMapper.finalize
|
19
|
+
DataMapper.auto_upgrade!
|
20
|
+
|
21
|
+
TEMPLATE
|
22
|
+
%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'cuba/generator'
|
2
|
+
|
3
|
+
describe Cuba::Generator do
|
4
|
+
subject { Cuba::Generator.new('myProject') }
|
5
|
+
|
6
|
+
it 'create_dir' do
|
7
|
+
expect(Dir).to receive(:mkdir)
|
8
|
+
subject.create_dir
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'create_config_file' do
|
12
|
+
expect(File).to receive(:open).with('./myproject/config.ru', 'w+')
|
13
|
+
subject.create_config_file
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'create_cuba_file' do
|
17
|
+
expect(File).to receive(:open).with('./myproject/myproject.rb', 'w+')
|
18
|
+
subject.create_cuba_file
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cuba-template-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Derek Viera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-07 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cuba
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: commander
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.3.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.3.0
|
83
|
+
description: Helps create cuba projects through a minimalist generator.
|
84
|
+
email:
|
85
|
+
- ma.dmviera01@gmail.com
|
86
|
+
executables:
|
87
|
+
- cuba
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/cuba
|
98
|
+
- cuba-template-generator.gemspec
|
99
|
+
- lib/cuba/generator.rb
|
100
|
+
- lib/cuba/generator/cli.rb
|
101
|
+
- lib/cuba/generator/version.rb
|
102
|
+
- lib/cuba/templates/api.erb
|
103
|
+
- lib/cuba/templates/app.erb
|
104
|
+
- lib/cuba/templates/gemfile.erb
|
105
|
+
- lib/cuba/templates/postgres.erb
|
106
|
+
- lib/cuba/templates/rack_config.erb
|
107
|
+
- spec/cuba_template_generator_spec.rb
|
108
|
+
homepage: ''
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Application Generator for Cuba framework.
|
132
|
+
test_files:
|
133
|
+
- spec/cuba_template_generator_spec.rb
|