remi-staticify 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +25 -1
  2. data/VERSION +1 -1
  3. data/bin/staticify +28 -13
  4. metadata +1 -1
@@ -1,3 +1,27 @@
1
1
  = Staticify
2
2
 
3
- ...
3
+ == Usage
4
+
5
+ Simple script for staticifying your Rack applications
6
+
7
+ staticify == %{ For staticifying your Rack applications }
8
+
9
+ Usage:
10
+ echo 'paths' | staticify # print this usage information
11
+ echo 'paths' | staticify . # staticify Rack app in current directory
12
+
13
+ Note:
14
+ staticify expects to get the paths to hit via STDIN
15
+
16
+ Options:
17
+ -d, --dir some/directory # directory to save files to
18
+ -a, --app "MyApp.new" # ruby to eval to get Rack app
19
+ -r, --require file[.rb] # ruby file(s) to require
20
+
21
+ == Notes
22
+
23
+ Checks for config.ru / Rails by default, otherwise you can:
24
+
25
+ $ staticify -r myapp.rb --app 'lambda {|env| [200, {}, "hi!"] }' info
26
+ $ staticify -r myapp.rb,another-file.rb --app 'Sinatra::Application' get '/'
27
+ $ staticify -r myapp --app 'MyApp.new' '/'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Simple script for staticifying your Rack applications
4
4
  #
5
- # Checks for config.ru / Rails by defualt, otherwise you can:
5
+ # Checks for config.ru / Rails by default, otherwise you can:
6
6
  #
7
7
  # $ staticify -r myapp.rb --app 'lambda {|env| [200, {}, "hi!"] }' info
8
8
  # $ staticify -r myapp.rb,another-file.rb --app 'Sinatra::Application' get '/'
@@ -26,6 +26,9 @@ def usage
26
26
  -d, --dir some/directory # directory to save files to
27
27
  -a, --app "MyApp.new" # ruby to eval to get Rack app
28
28
  -r, --require file[.rb] # ruby file(s) to require
29
+ -p, --paths "/,/foo,/bar" # specify paths (instead of STDIN)
30
+ -y, --dry-run # just print what we *would* do
31
+ -s, --save # don't delete dir before running
29
32
 
30
33
  USAGE
31
34
  end
@@ -37,14 +40,20 @@ end
37
40
 
38
41
  #### ==== Option Parsing ==== ####
39
42
 
40
- files_to_require = []
41
- ruby_to_run = nil
42
- path_to_cache_to = '.site'
43
+ files_to_require = []
44
+ ruby_to_run = nil
45
+ path_to_cache_to = '.site'
46
+ paths_to_cache = []
47
+ dry_run = false
48
+ overwrite_dir = true
43
49
 
44
50
  opts = OptionParser.new do |opts|
45
- opts.on('-r', '--require [file]') {|x| files_to_require << x }
46
- opts.on('-a', '--app [ruby]') {|x| ruby_to_run = x }
47
- opts.on('-d', '--dir [dir]') {|x| path_to_cache_to = x }
51
+ opts.on('-r', '--require [file]') {|x| files_to_require << x }
52
+ opts.on('-a', '--app [ruby]') {|x| ruby_to_run = x }
53
+ opts.on('-d', '--dir [dir]') {|x| path_to_cache_to = x }
54
+ opts.on('-p', '--paths [paths]') {|x| paths_to_cache = x.split(',') }
55
+ opts.on('-y', '--dry-run') { dry_run = true }
56
+ opts.on('-s', '--save') { overwrite_dir = false }
48
57
  end
49
58
  opts.parse! ARGV
50
59
 
@@ -74,9 +83,10 @@ end
74
83
 
75
84
  #### ==== Get Routes to Cache ==== ####
76
85
 
77
- paths_to_cache = []
78
- while path = gets
79
- paths_to_cache << path.strip
86
+ if paths_to_cache.empty?
87
+ while path = gets
88
+ paths_to_cache << path.strip
89
+ end
80
90
  end
81
91
 
82
92
  puts "Caching to #{ path_to_cache_to }"
@@ -85,11 +95,16 @@ puts "#{ paths_to_cache.length } paths to cache:"
85
95
 
86
96
  #### ==== Cache the Routes ==== ####"
87
97
 
88
- FileUtils.rm_rf path_to_cache_to
98
+ puts "rm -rf #{ path_to_cache_to }" if overwrite_dir
99
+ FileUtils.rm_rf path_to_cache_to if overwrite_dir && !dry_run
89
100
 
90
101
  RackBox.app = Rack::Staticifier.new(RackBox.app, :root => path_to_cache_to)
91
102
 
92
103
  paths_to_cache.each do |path|
93
- response = RackBox.request path
94
- puts " #{ response.status } #{ path }"
104
+ if dry_run
105
+ puts " #{ path }"
106
+ else
107
+ response = RackBox.request path
108
+ puts " #{ response.status } #{ path }"
109
+ end
95
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remi-staticify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi