sinistra 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4def2429dc298cba368338993f2f0b3f93c9b706
4
+ data.tar.gz: d3c51234db3d37dbd6dc1a18fd10922ee82bfb14
5
+ SHA512:
6
+ metadata.gz: d5c9e33549a654d8069e651da51f7bdfeb8b943f6a5a3bcdfc039d678b25e7c1c6c09d0a6d4da8ab93c162b41d52d4dd412a20f183b8340a69d03b518ad92995
7
+ data.tar.gz: 09980f2a660567544ebb97615ce24af91960ef9b2bd6872f23b8fa38407248ff7cfefe05b511f1a644d17a4fdc0618fd3b07796b249915dd7a427065b76c812b
@@ -0,0 +1,95 @@
1
+ #!/bin/sh
2
+ # **shoreman** is an implementation of the **Procfile** format. Inspired by
3
+ # the original [foreman](http://ddollar.github.com/foreman/) tool for ruby,
4
+ # as well as [norman](https://github.com/josh/norman) for node.js.
5
+
6
+ # Make sure that any errors cause the script to exit immediately.
7
+ set -e
8
+
9
+ # ## Usage
10
+
11
+ # Usage message that is displayed when `--help` is given as an argument.
12
+ #/ Usage: shoreman [<procfile>]
13
+ #/ Run Procfiles using shell.
14
+ #/
15
+ #/ The shoreman script reads commands from <procfile> and starts up the
16
+ #/ processes that it describes.
17
+
18
+ # Stolen from shocco. This formats the usage message above by grepping this
19
+ # file for lines starting with `#/`.
20
+ expr -- "$*" : ".*--help" >/dev/null && {
21
+ grep '^#/' <"$0" | cut -c4-
22
+ exit 0
23
+ }
24
+
25
+ # ## Logging
26
+
27
+ # For logging we want to prefix each entry with the current time, as well
28
+ # as the process name. This takes one argument, the name of the process, and
29
+ # then reads data from stdin, formats it, and sends it to stdout.
30
+ log() {
31
+ while read data
32
+ do
33
+ echo "$(date +"%H:%M:%S") $1\t| $data"
34
+ done
35
+ }
36
+
37
+ # ## Running commands
38
+
39
+ # When a process is started, we want to keep track of its pid so we can
40
+ # `kill` it when the parent process receives a signal, and so we can `wait`
41
+ # for it to finish before exiting the parent process.
42
+ store_pid() {
43
+ pids=("${pids[@]}" "$1")
44
+ }
45
+
46
+ # This starts a command asynchronously and stores its pid in a list for use
47
+ # later on in the script.
48
+ start_command() {
49
+ sh -c "$1" &
50
+ pid="$!"
51
+ store_pid "$pid"
52
+ }
53
+
54
+ # ## Reading the .env file if there is one
55
+
56
+ # The .env file needs to be a list of assignments like in a shell script.
57
+ # Only lines containing an equal sign are read, which means you can add comments.
58
+ # Preferably shell-style comments so that your editor print them like shell scripts.
59
+
60
+ ENV_FILE=${2:-'.env'}
61
+ if [ -f $ENV_FILE ]; then
62
+ while read line || [ -n "$line" ]; do
63
+ if [[ "$line" == *=* ]]; then
64
+ eval "export $line"
65
+ fi
66
+ done < "$ENV_FILE"
67
+ fi
68
+
69
+ # ## Reading the Procfile
70
+
71
+ # The Procfile needs to be parsed to extract the process names and commands.
72
+ # The file is given on stdin, see the `<` at the end of this while loop.
73
+ PROCFILE=${1:-'Procfile'}
74
+ while read line || [ -n "$line" ]; do
75
+ name=${line%%:*}
76
+ command=${line#*: }
77
+ start_command "$command"
78
+ echo "'${command}' started with pid ${pid}" | log "${name}.1"
79
+ done < "$PROCFILE"
80
+
81
+ # ## Cleanup
82
+
83
+ # When a `SIGINT`, `SIGTERM` or `EXIT` is received, this action is run, killing the
84
+ # child processes. The sleep stops STDOUT from pouring over the prompt, it
85
+ # should probably go at some point.
86
+ onexit() {
87
+ echo SIGINT received
88
+ echo sending SIGTERM to all processes
89
+ kill ${pids[*]} &>/dev/null
90
+ sleep 1
91
+ }
92
+ trap onexit SIGINT SIGTERM EXIT
93
+
94
+ # Wait for the children to finish executing before exiting.
95
+ wait
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'sinistra/cui'; Sinistra::CUI.start
@@ -0,0 +1,2 @@
1
+ puts "Why you're requiring a console utily anyway?"
2
+ require "sinistra/cui" # require the cui anyway, they're asking '-'
@@ -0,0 +1,234 @@
1
+ require 'thor'
2
+ require 'yaml'
3
+
4
+ def join(*args)
5
+ File.join(*args)
6
+ end
7
+
8
+ module Sinistra
9
+ class CUI < Thor
10
+
11
+ CONFIG_RU = <<eos
12
+ require '%appname%' # => ./lib/%appname%
13
+
14
+ %Appname%.run!
15
+ eos
16
+
17
+ LIB_APPNAME = <<eos
18
+ # this is a sample file, alter it to your needs
19
+ require 'sinatra'
20
+ require 'models/main'
21
+ require 'helpers/main'
22
+ require 'controller/main'
23
+
24
+ class %Appname% < Sinatra::Base
25
+ set :public_folder, './public'
26
+ set :views, './%appname%/view'
27
+ end
28
+ eos
29
+
30
+ LIB_MDL_MAIN = <<eos
31
+ # this is a sample file, alter it to your needs
32
+ # require 'models/sample'
33
+ eos
34
+
35
+ LIB_HLP_MAIN = <<eos
36
+ # this is a sample file, alter it to your needs
37
+ # require 'helpers/sample'
38
+ eos
39
+
40
+ LIB_CTRLMAIN = <<eos
41
+ # this is a sample file, alter it to your needs:
42
+
43
+ # this is sample organization (good for small apps):
44
+ # require 'controller/before'
45
+ # require 'controller/get'
46
+ # require 'controller/post'
47
+ # require 'controller/put'
48
+ # require 'controller/patch'
49
+ # require 'controller/delete'
50
+ # require 'controller/options'
51
+ # require 'controller/link'
52
+ # require 'controller/unlink'
53
+ # require 'controller/after'
54
+
55
+ # bigger apps might need a per-function organization
56
+ # like 'controller/blog', 'controller/profile' and etc
57
+ eos
58
+
59
+ README = <<eos
60
+ sample readme
61
+ eos
62
+
63
+ LICENSE = <<eos
64
+ sample license
65
+ eos
66
+
67
+ TODO = <<eos
68
+ sample todo task
69
+ eos
70
+
71
+ desc "init AppName", "initiates a new sinistra app with given filename"
72
+ def init(name)
73
+ if not File.exists?("#{name}.sinistra")
74
+ # default configuration
75
+ default_yaml = {
76
+ "name" => name,
77
+ "readme" => true,
78
+ "todo" => true,
79
+ "license" => false,
80
+ "bundler" => {
81
+ "enabled" => true,
82
+ "source" => "https://rubygems.org",
83
+ "ruby" => "2.0.0",
84
+ "gems" => {"sinatra"=>"", "thin"=>""}
85
+ },
86
+ "proc" => {
87
+ "enabled" => true,
88
+ "env" => {
89
+ "PORT" => "8080"
90
+ },
91
+ "tasks" => {
92
+ "web" => "bundle exec rackup -I ./ -I ./lib -I ./%appname% -I ./thrd -P $PORT"
93
+ }
94
+ },
95
+ "hooks" => {
96
+ "git" => true,
97
+ "model" => true,
98
+ "helper" => true,
99
+ "hg" => false,
100
+ "sql" => false,
101
+ "rdoc" => false,
102
+ "logs" => false,
103
+ "tests" => false,
104
+ "vendor" => false
105
+ },
106
+ }
107
+
108
+ # saves config.yml
109
+ IO.write("config.yml", default_yaml.to_yaml)
110
+
111
+ # warns about completion
112
+ puts " ! Edit you config.yml and then run `sinistra install'"
113
+ else
114
+ puts " ! Failed to create the app: already found a config.yml"
115
+ end
116
+ end
117
+
118
+ desc "install", "install sinistra structure layer"
119
+ def install
120
+ config = YAML.load(IO.read("config.yml"))
121
+ name = config["name"]
122
+
123
+ makdir = [name.downcase, join(name.downcase, "controller"), join(name.downcase, "views"), join(name.downcase, "views", "layouts"), "lib", "public", "tmp"]
124
+
125
+ # optional but default model
126
+ makdir << join(name.downcase, "models") if config["hooks"]["model"]
127
+ makdir << join(name.downcase, "helpers") if config["hooks"]["helper"]
128
+
129
+ # extra hooks
130
+ makdir << "db" if config["hooks"]["sql"]
131
+ makdir << "doc" if config["hooks"]["rdoc"]
132
+
133
+ # extra things
134
+ makdir << "misc" if config["hooks"]["tests"] || config["hooks"]["vendor"]
135
+
136
+ # tests, init scripts and vendor code
137
+ makdir << "misc/tests" if config["hooks"]["tests"]
138
+ makdir << "misc/thrd" if config["hooks"]["vendor"]
139
+
140
+ # create dirs
141
+ makdir.each do |dir|
142
+ begin
143
+ Dir.mkdir(dir)
144
+ rescue
145
+ end
146
+ end
147
+
148
+ # creating base files
149
+ CONFIG_RU.gsub!(/\%appname\%/, name.downcase)
150
+ CONFIG_RU.gsub!(/\%Appname\%/, name.capitalize)
151
+ CONFIG_RU.gsub!(/\%APPNAME\%/, name.upcase)
152
+ CONFIG_RU.gsub!(/^.*require\s\'models\/main\'$/, "") unless config["hooks"]["model"]
153
+ CONFIG_RU.gsub!(/^.*require\s\'helpers\/main\'$/, "") unless config["hooks"]["helper"]
154
+
155
+ # library name
156
+ LIB_APPNAME.gsub!(/\%appname\%/, name.downcase)
157
+ LIB_APPNAME.gsub!(/\%Appname\%/, name.capitalize)
158
+ LIB_APPNAME.gsub!(/\%APPNAME\%/, name.upcase)
159
+
160
+ # writing files
161
+ IO.write("config.ru", CONFIG_RU) unless File.exists?("config.ru")
162
+ IO.write("./lib/#{name.downcase}.rb", LIB_APPNAME) unless File.exists?("./lib/#{name.downcase}.rb")
163
+ IO.write("./#{name.downcase}/controller/main.rb", LIB_CTRLMAIN) unless File.exists?("./#{name.downcase}/controller/main.rb")
164
+
165
+ # optional base files
166
+ IO.write(join(name.downcase,"models","main.rb"), LIB_MDL_MAIN) if config["hooks"]["model"] && !File.exists?(join(name.downcase,"models","main.rb"))
167
+ IO.write(join(name.downcase,"helpers","main.rb"), LIB_HLP_MAIN) if config["hooks"]["helper"] && !File.exists?(join(name.downcase,"helpers","main.rb"))
168
+
169
+ # create misc files
170
+ IO.write("README", README) if config["hooks"]["readme"] && !File.exists?("README")
171
+ IO.write("LICENSE", LICENSE) if config["hooks"]["license"] && !File.exists?("LICENSE")
172
+ IO.write("TODO", TODO) if config["hooks"]["todo"] && !File.exists?("TODO")
173
+
174
+ # gemfile creation
175
+ if config["bundler"]["enabled"] && !File.exists?("Gemfile")
176
+ puts "Gemfile.lock found, overwriting it anyway" if File.exists?("Gemfile.lock")
177
+ gemfile = "ruby '#{config["bundler"]["ruby"]}'\n"
178
+ gemfile << "source '#{config["bundler"]["source"]}'\n"
179
+ config["bundler"]["gems"].each do |name_, version|
180
+ gemfile << "gem '#{name_}'"
181
+ gemfile << ", '#{version}'" unless version == ""
182
+ gemfile << "\n"
183
+ end
184
+ IO.write("Gemfile", gemfile)
185
+ puts " ! Run `bundle install' to install #{name} dependencies get a proper Gemfile.lock"
186
+ end
187
+
188
+ # git creation args
189
+ if config["hooks"]["git"]
190
+ %x{ git init } unless File.exists?(".git")
191
+ IO.write(".gitignore", "/tmp/*\n/log/*\n") unless File.exists?(".gitignore")
192
+ end
193
+
194
+ # mercurial creation args
195
+ if config["hooks"]["hg"]
196
+ %x{ hg init } unless File.exists?(".hg")
197
+ IO.write(".hgignore", "syntax: glob\n/tmp/*\n/log/*\n") unless File.exists?(".hgignore")
198
+ end
199
+
200
+ if config["proc"]["enabled"]
201
+ unless File.exists?("Procfile")
202
+ procfile = ""
203
+ config["proc"]["tasks"].each do |task, action|
204
+ procfile << task << ": " << action << "\n"
205
+ end
206
+ procfile.gsub!(/\%appname\%/, name.downcase)
207
+ procfile.gsub!(/\%Appname\%/, name.capitalize)
208
+ procfile.gsub!(/\%APPNAME\%/, name.upcase)
209
+ IO.write("Procfile", procfile)
210
+ end
211
+ unless File.exists?(".env")
212
+ env = ""
213
+ config["proc"]["env"].each do |nm, value|
214
+ env << nm << "=" << value << "\n"
215
+ end
216
+ env.gsub!(/\%appname\%/, name.downcase)
217
+ env.gsub!(/\%Appname\%/, name.capitalize)
218
+ env.gsub!(/\%APPNAME\%/, name.upcase)
219
+ IO.write(".env", env)
220
+ end
221
+ end
222
+
223
+ # Lastest warnings
224
+ puts " ! Run `foreman start' (or the built-in `sinistra start') to launch #{config["name"]}'s Procfile"
225
+ end
226
+
227
+ desc "start", "runs the sinistra application"
228
+ def start
229
+ script = File.dirname(File.expand_path(__FILE__))
230
+ script = join(script,"..","..","bin","shoreman.sh") # exiting /sinistra/lib
231
+ exec "\"#{script}\""
232
+ end
233
+ end
234
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinistra
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Ferraz Lemos de Sousa / @kress95
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ description: Builds Sinatra apps with a enforced structure.
28
+ email: cferraz95@gmail.com
29
+ executables:
30
+ - sinistra
31
+ - shoreman.sh
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/sinistra.rb
36
+ - lib/sinistra/cui.rb
37
+ - bin/sinistra
38
+ - bin/shoreman.sh
39
+ homepage: https://github.com/kress95/sinistra
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Sinatra project generator :D
63
+ test_files: []