prestruct 0.1.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 +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/bin/prestruct +35 -0
- data/lib/prestruct/contents.rb +66 -0
- data/lib/prestruct/folder.rb +42 -0
- data/lib/prestruct/sinstruct.rb +91 -0
- data/lib/prestruct/version.rb +3 -0
- data/lib/prestruct.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c23bc41f37cc64757d4d5fad96df37d4d81d552158db70d88ec4ed422917e30
|
4
|
+
data.tar.gz: 4f476b3858310e063c3a49f2897946c8b76e5ac51c8a78d7b8227a547f40e3f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7492eb6fc082734f22af276d70196f8a6b407e02216ac3594ab8cff8fbfda23334823dac9dfd5951d2c47520d24d9ed9bc94220fe2065cabadde003619273f97
|
7
|
+
data.tar.gz: 3726582dcbb0a65389bc89f1a8f43d69810f5db628494cb10434df62956d7bd1743e41cc420390db9ab7485f4a6cfa9f1051dc82bd48a3293da115b692e75261
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Lokalise team, Ilya Bodrov
|
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
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Prestruct: A Ruby gem that builds common project file structures for you
|
2
|
+
|
3
|
+
Prestruct is a minimalist CLI ruby gem that creates the basic file structures for different formats of ruby projects.Currently only supports Sinatra single file and mvc projects.
|
4
|
+
|
5
|
+
*Mostly for expirementation and personal usage so the structuring is semi-opinionated.*
|
6
|
+
|
7
|
+
**Installation**
|
8
|
+
To install from the command line:
|
9
|
+
```
|
10
|
+
gem install prestruct
|
11
|
+
```
|
12
|
+
**Usage**
|
13
|
+
Once installed, Prestruct can be used anywhere from the command line. Navigate to the directory you plan to place your project in then:
|
14
|
+
```
|
15
|
+
prestruct [Project type (sinatra)] [structure (simple, mvc)] [-n project_name]
|
16
|
+
```
|
17
|
+
After your preferred project type, input your preferred file structure. You can also specify a title for your project with `-n` or `--name`. If unspecified, the project name will default to `new_project`.
|
18
|
+
|
19
|
+
**Example Usage**
|
20
|
+
```
|
21
|
+
prestruct sinatra mvc -n word_analyzer
|
22
|
+
# creates a mvc sinatra project with the name 'word_analyzer'
|
23
|
+
|
24
|
+
prestruct sinatra simple
|
25
|
+
# creates a single file sinatra project with default name 'project_name'
|
26
|
+
```
|
27
|
+
|
28
|
+
**Additional Options**
|
29
|
+
```
|
30
|
+
-v, --version # shows the current version of Prestruct installed
|
31
|
+
-h, --help # shows the argument structure that Prestruct accepts
|
32
|
+
-n, --name # used alongside a project type to specify a project name
|
33
|
+
```
|
data/bin/prestruct
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'prestruct'
|
4
|
+
require 'slop'
|
5
|
+
|
6
|
+
opts = Slop.parse do |o|
|
7
|
+
o.string 'sinatra', 'create sinatra project', suppress_errors: true
|
8
|
+
o.string '-n', '--name', 'project name', suppress_errors: true
|
9
|
+
o.on '-h', '--help' do
|
10
|
+
puts 'Usage: prestruct [sinatra mvc/simple] [-n project name]'
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
o.on '-v', '--version' do
|
14
|
+
puts 'prestruct v0.1.0'
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
args = opts.to_hash
|
20
|
+
|
21
|
+
args[:name] ||= 'project_name'
|
22
|
+
if args[:sinatra]
|
23
|
+
case args[:sinatra]
|
24
|
+
when "simple"
|
25
|
+
puts "prestructing..."
|
26
|
+
SinStruct::Base.new(args[:name])
|
27
|
+
when "mvc"
|
28
|
+
puts "prestructing..."
|
29
|
+
SinStruct::Mvc.new(args[:name])
|
30
|
+
else
|
31
|
+
puts "Please specify either 'simple' or 'mvc' after 'sinatra'"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "Usage: prestruct [sinatra mvc/simple] [-n project_name]"
|
35
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module FileContents
|
2
|
+
class << self
|
3
|
+
def css
|
4
|
+
["styles.css", "css here"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def readme
|
8
|
+
["README.MD", "Description and installation instructions for project here"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Sinatra
|
13
|
+
class << self
|
14
|
+
def gemfile
|
15
|
+
["Gemfile", "source 'https://rubygems.org'"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def model
|
19
|
+
["model.rb", "# data management classes and code here"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def view
|
23
|
+
contents = <<~FILE
|
24
|
+
<!--view content here-->
|
25
|
+
FILE
|
26
|
+
["view.erb", contents]
|
27
|
+
end
|
28
|
+
|
29
|
+
def layout
|
30
|
+
contents = <<~FILE
|
31
|
+
<!doctype html>
|
32
|
+
<html lang="en-US">
|
33
|
+
<head>
|
34
|
+
<title>Rec Analyzer</title>
|
35
|
+
<meta charset="UTF-8">
|
36
|
+
<link rel="stylesheet" type="text/css" href="<%= url('/stylesheets/styles.css') %>">
|
37
|
+
</head>
|
38
|
+
<body></body>
|
39
|
+
</html>
|
40
|
+
FILE
|
41
|
+
['layout.erb', contents]
|
42
|
+
end
|
43
|
+
|
44
|
+
def controller(project_name)
|
45
|
+
contents = <<~FILE
|
46
|
+
require 'sinatra'
|
47
|
+
# view controller
|
48
|
+
# routes go here
|
49
|
+
FILE
|
50
|
+
["#{project_name}.rb", contents]
|
51
|
+
end
|
52
|
+
|
53
|
+
def config
|
54
|
+
["config.ru", "require 'route_to_controller'\nrun Sinatra::Application"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def helpers
|
58
|
+
["helpers.rb", "# helper methods go here"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def spec(project_name)
|
62
|
+
["#{project_name}_test.rb", "require 'route_to_controller'\n# tests for project go here"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Folder
|
2
|
+
attr_accessor :files, :folders
|
3
|
+
def initialize(name)
|
4
|
+
@path = name
|
5
|
+
@files = []
|
6
|
+
@folders = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_files(*files)
|
10
|
+
files.each do |file|
|
11
|
+
@files << {path: "#{@path}/#{file[0]}", contents: file[1]}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_folder(name)
|
16
|
+
# consider making splat argument and being able to add multiple folders
|
17
|
+
@folders[name.to_s] = Folder.new("#{@path}/#{name}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
# create own directory
|
22
|
+
Dir.mkdir(@path)
|
23
|
+
|
24
|
+
# create all files within directory
|
25
|
+
@files.each { |file| rw_file(file[:path], file[:contents]) } unless @files.empty?
|
26
|
+
|
27
|
+
# for each folder in @folders, run create method
|
28
|
+
@folders.values.each { |folder| folder.create } unless @folders.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
@path
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def rw_file(root, contents = "")
|
38
|
+
File.open(root, "w+") do |f|
|
39
|
+
f.write contents
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative 'folder.rb'
|
2
|
+
require_relative 'contents.rb'
|
3
|
+
|
4
|
+
module SinStruct
|
5
|
+
class Base
|
6
|
+
include FileContents
|
7
|
+
include FileContents::Sinatra
|
8
|
+
|
9
|
+
# Considering making entire class class methods
|
10
|
+
def initialize(project_name)
|
11
|
+
@project_name = project_name
|
12
|
+
construct
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def construct
|
18
|
+
# create folder object with name
|
19
|
+
@root = Folder.new(@project_name)
|
20
|
+
# create app dir > add all files to it
|
21
|
+
build_app
|
22
|
+
# create public dir > add all files
|
23
|
+
build_public
|
24
|
+
# add loose files to folder
|
25
|
+
build_loose_files
|
26
|
+
# create folder
|
27
|
+
@root.create
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_app
|
31
|
+
@app = @root.add_folder("app")
|
32
|
+
@app.add_files(Sinatra.controller(@root))
|
33
|
+
build_views
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_views
|
37
|
+
@views = @app.add_folder("views")
|
38
|
+
@views.add_files(Sinatra.view, Sinatra.layout)
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_public
|
42
|
+
@public = @root.add_folder("public")
|
43
|
+
@public.add_files(FileContents.css)
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_loose_files
|
47
|
+
@root.add_files(Sinatra.config, Sinatra.gemfile, FileContents.readme)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Mvc < Base
|
52
|
+
def construct
|
53
|
+
@root = Folder.new(@project_name)
|
54
|
+
build_app
|
55
|
+
build_public
|
56
|
+
build_specs
|
57
|
+
build_loose_files
|
58
|
+
@root.create
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def build_app
|
64
|
+
@app = @root.add_folder("app")
|
65
|
+
build_models
|
66
|
+
build_controller
|
67
|
+
build_views
|
68
|
+
build_helpers
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_models
|
72
|
+
@models = @app.add_folder("models")
|
73
|
+
@models.add_files(Sinatra.model)
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_controller
|
77
|
+
@controllers = @app.add_folder("controllers")
|
78
|
+
@controllers.add_files(Sinatra.controller(@root))
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_helpers
|
82
|
+
@helpers = @app.add_folder("helpers")
|
83
|
+
@helpers.add_files(Sinatra.helpers)
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_specs
|
87
|
+
@specs = @app.add_folder("specs")
|
88
|
+
@specs.add_files(Sinatra.spec(@root))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/prestruct.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prestruct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Palpallatoc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.9.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.9.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 13.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 13.0.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.0.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.0.0
|
55
|
+
description: Generates the (semi-opinianated) basic file structure for a ruby project
|
56
|
+
in users current directory. Currently only supports Sinatra projects.
|
57
|
+
email:
|
58
|
+
- tomasphn@gmail.com
|
59
|
+
executables:
|
60
|
+
- prestruct
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- CHANGELOG.md
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- bin/prestruct
|
68
|
+
- lib/prestruct.rb
|
69
|
+
- lib/prestruct/contents.rb
|
70
|
+
- lib/prestruct/folder.rb
|
71
|
+
- lib/prestruct/sinstruct.rb
|
72
|
+
- lib/prestruct/version.rb
|
73
|
+
homepage: https://github.com/tomasphn/prestruct
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.5.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.3.23
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Builds basic file structure for a ruby project
|
96
|
+
test_files: []
|