franky 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0057e29b78c1a61b00c4427be19fc10011b492d
4
+ data.tar.gz: 104eee8474df2f0196ac90d857512930f350eb4e
5
+ SHA512:
6
+ metadata.gz: 4b8ed29f02a5f74a52e4d8a7ee113382e5a002d295b0144fd30e683ea48e2187712f677f1aea6421c842ce925f9750dd366ce4bf76540c100f3ac4781859cb1c
7
+ data.tar.gz: 2ef2b43541795a01cc0176dc747d1ffdda98c40843e5c03b98ebed66411c746572072026053f44565afb358243e49f38a3a6672fe33adf81cb03e4c9134150c9
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in franky.gemspec
4
+ gemspec
5
+ gem 'thor'
6
+ gem 'colorize'
@@ -0,0 +1,90 @@
1
+ # Franky
2
+
3
+ A site generator for minimal Sinatra template. Check [Sinatra](http://www.sinatrarb.com/) if you don't know what it is.
4
+
5
+ ## Installation 安裝
6
+
7
+ ```
8
+ $ gem install franky
9
+ ```
10
+
11
+ ## Generation 產生專案
12
+
13
+ Under the directory you want to create your project, run:
14
+
15
+ ```
16
+ $ franky
17
+ ```
18
+ which prompts a message to let you specify a directory name.
19
+
20
+ Or simply run:
21
+
22
+ ```
23
+ $ franky new my_project
24
+ ```
25
+
26
+ Replace "my_project" with your project name.
27
+
28
+ ## Configuration 設定
29
+
30
+ There are two templates: default template & minimal template. They can be specified in commands.
31
+
32
+ Add `-m` at the end if you want to create a minimal template. For example,
33
+
34
+ ```
35
+ $ franky -m
36
+ ```
37
+ or
38
+
39
+ ```
40
+ $ franky new my_project -m
41
+ ```
42
+
43
+ If nothing is specified, the template is set to default.
44
+
45
+ ## Templates 版型說明
46
+
47
+ ### Default Template
48
+
49
+ This template includes 3 parts:
50
+
51
+ <p style="color: blue">1. Rack configuration</p>
52
+
53
+ - Gemfile
54
+ - config.ru
55
+
56
+ <p style="color: blue">2. The app</p>
57
+
58
+ - app/app.rb
59
+ - app/views/layout.html.erb
60
+ - app/views/index.html.erb
61
+
62
+ <p style="color: blue">3. Assets</p>
63
+
64
+ - public/js/app.js
65
+ - public/css/style.css
66
+
67
+ ### Minimal Template
68
+
69
+ It contains only 3 files:
70
+ - Gemfile
71
+ - app.rb
72
+ - config.ru
73
+
74
+ This is the minimal requirement for deployment. Check the following part if you want to deploy to Heroku.
75
+
76
+ ## Initialization 開始
77
+
78
+ After generation, enter the project, run `$ bundle` and you are all set. Use `$ rackup` or `$ shotgun` to run local server as usual. You should see "hello world" if everything works fine.
79
+
80
+ ## Deployment 佈署
81
+
82
+ For the simplest deployment, check [Heroku](https://devcenter.heroku.com/articles/rack#sinatra) for more information.
83
+
84
+ ## Reference 參考資料
85
+
86
+ For a more powerful template generator, check [hazel](https://github.com/c7/hazel), which contains configuration on test, db, ruby version, git, and more.
87
+
88
+ ## Feedback 回饋
89
+
90
+ Send to nkj20932@hotmail.com for any feedback. Create an issue if you find any problem. Thanks!
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/task"
3
+
@@ -0,0 +1,5 @@
1
+ #!usr/bin/env ruby
2
+
3
+ require 'franky'
4
+
5
+ Franky::Base.start ARGV
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'shotgun'
5
+ gem 'rake'
@@ -0,0 +1,7 @@
1
+ require 'sinatra'
2
+
3
+ class App < Sinatra::Base
4
+ get "/" do
5
+ "Hello world"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'sinatra'
2
+
3
+ class App < Sinatra::Base
4
+ get "/" do
5
+ erb :'index.html'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require './app/app'
2
+
3
+ run App
@@ -0,0 +1 @@
1
+ <p>Hello World</p>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <script type="text/javascript" src="js/app.js"></script>
6
+ <link rel="stylesheet" type="text/css" href="css/style.css">
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,6 @@
1
+ require "franky/version"
2
+ require "franky/base"
3
+
4
+ module Franky
5
+
6
+ end
@@ -0,0 +1,62 @@
1
+ require 'franky/file_handler'
2
+ require 'thor'
3
+ require 'colorize'
4
+
5
+ module Franky
6
+ class Base < Thor
7
+
8
+ default_task :new
9
+ desc "new [dir_name] [options]", "creates a project with minimal setup"
10
+ option :minimal, type: :boolean, default: false, aliases: "-m"
11
+ def new dir_name=nil
12
+ unless dir_name_given?(dir_name)
13
+ dir_name = specify_dir
14
+ end
15
+
16
+ dir_name = dir_name.gsub("\n", "")
17
+ return unless dir_valid?(dir_name)
18
+
19
+ if options[:minimal]
20
+ FileHandler.new.minimal_template(dir_name)
21
+ else
22
+ FileHandler.new.default_template(dir_name)
23
+ end
24
+ end
25
+
26
+ # 將--version和-v指令轉入__print_version
27
+ # prefix底線是為了避免變成一般的thor command
28
+ map %w[--version -v] => :__print_version
29
+ desc "--version, -v", "show version"
30
+ def __print_version
31
+ puts Franky::VERSION
32
+ end
33
+
34
+ private
35
+
36
+ def dir_name_given?(dir_name)
37
+ dir_name == nil ? false : true
38
+ end
39
+
40
+ def specify_dir
41
+ print "specify a directroy name: "
42
+ # 只要command有帶參數,Ruby預設gets會去抓第一個變數當做檔案名稱,所以要指明$stdin.gets當做user input
43
+ dir_name = $stdin.gets
44
+ dir_name
45
+ end
46
+
47
+ def dir_valid?(dir_name)
48
+ if dir_name == ""
49
+ puts "No directory name is given"
50
+ return false
51
+ end
52
+
53
+ if Dir.exist? dir_name
54
+ puts "'#{dir_name}' already exists. Please rename.".red
55
+ return false
56
+ end
57
+
58
+ true
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,81 @@
1
+ class FileHandler
2
+
3
+ # def self.read file_name
4
+ # File.read(File.expand_path("../../files/#{file_name}", __FILE__))
5
+ # end
6
+
7
+ # def self.create dir, file, content
8
+ # File.open("#{dir}/#{file}", 'w+') {|f| f.write(content)}
9
+ # end
10
+
11
+ def self.copy file_name, dir_name, new_file_name
12
+ FileUtils.cp File.expand_path("../../files/#{file_name}", __FILE__), "#{dir_name}/#{new_file_name}"
13
+ end
14
+
15
+ def minimal_template dir_name
16
+ puts "Creating minimal Sinatra project '#{dir_name}'..."
17
+
18
+ Dir.mkdir dir_name
19
+ puts "Created ".green + "#{dir_name}/"
20
+
21
+ FileHandler.copy "config.ru", dir_name, "config.ru"
22
+ puts "Created ".green + "#{dir_name}/config.ru"
23
+
24
+ FileHandler.copy "Gemfile", dir_name, "Gemfile"
25
+ puts "Created ".green + "#{dir_name}/Gemfile"
26
+
27
+ FileHandler.copy "app.min.rb", dir_name, "app.rb"
28
+ puts "Created ".green + "#{dir_name}/app.rb"
29
+
30
+ puts "Done!".green
31
+ end
32
+
33
+ def default_template dir_name
34
+ puts "Creating default Sinatra project '#{dir_name}'..."
35
+
36
+ Dir.mkdir dir_name
37
+ puts "Created ".green + "#{dir_name}/"
38
+
39
+ FileHandler.copy "config.ru", dir_name, "config.ru"
40
+ puts "Created ".green + "#{dir_name}/config.ru"
41
+
42
+ FileHandler.copy "Gemfile", dir_name, "Gemfile"
43
+ puts "Created ".green + "#{dir_name}/Gemfile"
44
+
45
+ File.open("#{dir_name}/README.md", 'w+') {|f| f.write("\nPowered by [Franky](https://github.com/nkj20932/franky)")}
46
+ puts "Created ".green + "#{dir_name}/README.md"
47
+
48
+ Dir.mkdir "#{dir_name}/app"
49
+ puts "Created ".green + "#{dir_name}/app/"
50
+
51
+ FileHandler.copy "app.rb", "#{dir_name}/app", "app.rb"
52
+ puts "Created ".green + "#{dir_name}/app.rb"
53
+
54
+ Dir.mkdir "#{dir_name}/app/views"
55
+ puts "Created ".green + "#{dir_name}/app/views/"
56
+
57
+ FileHandler.copy "layout.html.erb", "#{dir_name}/app/views", "layout.html.erb"
58
+ puts "Created ".green + "#{dir_name}/app/views/layout.html.erb"
59
+
60
+ FileHandler.copy "index.html.erb", "#{dir_name}/app/views", "index.html.erb"
61
+ puts "Created ".green + "#{dir_name}/app/views/index.html.erb"
62
+
63
+ Dir.mkdir "#{dir_name}/public"
64
+ puts "Created ".green + "#{dir_name}/public/"
65
+
66
+ Dir.mkdir "#{dir_name}/public/js"
67
+ puts "Created ".green + "#{dir_name}/public/js"
68
+
69
+ File.open("#{dir_name}/public/js/app.js", 'w+')
70
+ puts "Created ".green + "#{dir_name}/public/js/app.js"
71
+
72
+ Dir.mkdir "#{dir_name}/public/css"
73
+ puts "Created ".green + "#{dir_name}/public/css"
74
+
75
+ File.open("#{dir_name}/public/css/style.css", 'w+')
76
+ puts "Created ".green + "#{dir_name}/public/js/style.css"
77
+
78
+ puts "Done!".green
79
+ end
80
+
81
+ end
@@ -0,0 +1,3 @@
1
+ module Franky
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: franky
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adler Hsieh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-27 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: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.19'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Generates a Sinatra project containing only necessary files
70
+ email:
71
+ - nkj20932@hotmail.com
72
+ executables:
73
+ - franky
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - bin/franky
81
+ - lib/files/Gemfile
82
+ - lib/files/app.min.rb
83
+ - lib/files/app.rb
84
+ - lib/files/config.ru
85
+ - lib/files/index.html.erb
86
+ - lib/files/layout.html.erb
87
+ - lib/franky.rb
88
+ - lib/franky/base.rb
89
+ - lib/franky/file_handler.rb
90
+ - lib/franky/version.rb
91
+ homepage: https://github.com/nkj20932/franky
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Generates a minimal Sinatra project
115
+ test_files: []