fir 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -59,6 +59,8 @@ Check `httpd.conf` syntax and restart Apache:
59
59
 
60
60
  That should do it.
61
61
 
62
+ If you can't make this work, there's a workaround: you can export your whole site to static HTML. See "Exporting to HTML" below.
63
+
62
64
  Basic Usage
63
65
  ===========
64
66
 
@@ -100,6 +102,16 @@ Fir's API uses HTTP basic authentication. The users list is stored in `users.yml
100
102
 
101
103
  rake users:add user=username pass=password
102
104
 
105
+ ## Exporting to HTML ##
106
+
107
+ You can export your whole site to static HTML. If you deploy that, the only thing you'll need on your server is mod_rewrite. To export:
108
+
109
+ rake export dir=~/sites/exported_example
110
+
111
+ The export task boots a Rackup server and accesses each page to generate the cache. It then copies the cache and the rest of the public folder to the output directory. By default, Rackup runs on port 9292. You can make it use a different port like this:
112
+
113
+ rake export dir=~/sites/exported_example port=3000
114
+
103
115
  Webserver Support
104
116
  =================
105
117
 
@@ -107,7 +119,7 @@ Fir is designed primarily for Phusion Passenger. As a Rack-based framework, it t
107
119
 
108
120
  As of this writing, Fir has only been tested with Rackup, Passenger, and CGI. If you get Fir working with anything else, please visit Fir's GitHub repository and let us know how you did it.
109
121
 
110
- By the way, using CGI in production is **not** recommended. CGI boots a new Fir instance on every request. Fir is a pretty lightweight framework, so the load time isn't huge, but that doesn't mean CGI is a good idea. If you understand the issues with CGI and still want to use it, go ahead and take a look at [`dispatch.cgi`](http://github.com/jarrett/fir-example/blob/master/public/dispatch.cgi) in the example.
122
+ By the way, using CGI in production is **not** recommended. CGI boots a new Fir instance on every request. Fir is a pretty lightweight framework, so the load time isn't huge, but that doesn't mean CGI is a good idea. If you understand the issues with CGI and still want to use it, go ahead and take a look at [`dispatch.cgi`](http://github.com/jarrett/fir-example/blob/master/public/dispatch.cgi) in the example site.
111
123
 
112
124
  Unicode and Others
113
125
  ==================
data/example/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ FIR_ROOT = File.expand_path(File.dirname(__FILE__))
2
+
1
3
  require 'rubygems'
2
4
  require 'fir'
3
5
 
data/lib/fir/boot.rb CHANGED
@@ -7,6 +7,10 @@ module Fir
7
7
  # directory fixes that.
8
8
  Dir.chdir(FIR_ROOT)
9
9
  ::Fir.validate_config
10
+ # This allows us to invoke Rackup with -e "FORCE_CACHING = true"
11
+ if defined?(FORCE_CACHING) and FORCE_CACHING
12
+ Fir.config.perform_caching = true
13
+ end
10
14
  #use ::Rack::Reloader # Only when developing the Fir gem
11
15
  use ::Rack::ContentLength
12
16
  use ::Fir::Static
data/lib/fir/tasks.rb CHANGED
@@ -27,6 +27,95 @@ module Fir
27
27
  end
28
28
  end
29
29
  end
30
+ desc 'Export the site to static HTML. (For web hosts that can\'t support Rack. But mod_rewrite must be enabled for .htaccess!) ' +
31
+ 'This will temporarily run Rackup on port 3000 or another port you specify. Usage: rake export dir=path_to_export_to [port=3000]'
32
+ task :export do
33
+ require 'fileutils'
34
+
35
+ if !ENV.has_key?('dir') or ENV['dir'].empty?
36
+ raise(ArgumentError, 'Usage: rake export dir=path_to_export_to [port=3000]')
37
+ end
38
+
39
+ port = ENV['port'] || 9292
40
+
41
+ pid_file = 'cache_gen_server.pid'
42
+
43
+ puts 'Starting Rackup with caching turned on...'
44
+ fork do
45
+ exec %Q{rackup -p #{port} -e "FORCE_CACHING = true" -D --pid #{pid_file}}
46
+ end
47
+ sleep(1) # Give the server a moment to boot
48
+
49
+ page_config = YAML.load(File.read(File.join(FIR_ROOT, 'pages.yml')))
50
+ path_mappings = page_config.inject({}) do |mappings, (page, configs)|
51
+ mappings[configs['path']] = page if configs['path']
52
+ mappings
53
+ end
54
+ inverted_path_mappings = path_mappings.invert
55
+
56
+ pages_dir = File.join(FIR_ROOT, 'pages')
57
+ # Get all the page files without extensions
58
+ paths = Dir.glob(pages_dir + '/**/**').inject([]) do |result, file|
59
+ file.gsub!(pages_dir + '/', '')
60
+ file.gsub!(/#{File.extname(file)}$/, '')
61
+ unless inverted_path_mappings.has_key?(file)
62
+ result << file
63
+ end
64
+ result
65
+ end + path_mappings.keys
66
+
67
+ puts 'Getting each page to generate the cache...'
68
+
69
+ paths.each do |path|
70
+ getter = lambda { Net::HTTP.get(URI.parse("http://localhost:#{port}/#{path}")) }
71
+ failure_count = 0
72
+ giving_up = false
73
+ success = false
74
+ while failure_count <= 3 and !success
75
+ puts ' GET ' + path
76
+ begin
77
+ getter.call
78
+ success = true
79
+ rescue
80
+ failure_count += 1
81
+ if failure_count <= 3
82
+ puts ' Could not connect. Retrying.'
83
+ sleep(1)
84
+ else
85
+ puts ' Could not connect. Giving up.'
86
+ giving_up = true
87
+ end
88
+ end
89
+ end
90
+ break if giving_up
91
+ end
92
+
93
+ server_pid = File.read(pid_file).to_i
94
+ Process.kill('SIGINT', server_pid)
95
+ File.delete(pid_file)
96
+
97
+ copy_from = File.join(FIR_ROOT, 'public', '.')
98
+ copy_to = ENV['dir']
99
+ unless File.exists?(copy_to)
100
+ Dir.mkdir(copy_to)
101
+ end
102
+ FileUtils.cp_r(copy_from, copy_to)
103
+ FileUtils.cp_r(File.join(copy_to, 'cache', '.'), copy_to)
104
+ FileUtils.rm_rf(File.join(copy_to, 'cache'))
105
+ ['.htaccess', 'dispatch.cgi'].each do |file|
106
+ File.delete(File.join(copy_to, file))
107
+ end
108
+ # Create a simple .htaccess file to enable pretty URLs
109
+ htaccess =
110
+ "DirectoryIndex index.html\n" +
111
+ "RewriteEngine On\n" +
112
+ "RewriteCond %{REQUEST_FILENAME} !-f\n" +
113
+ "RewriteCond %{REQUEST_FILENAME} !-d\n" +
114
+ "RewriteRule (.*) $1.html"
115
+ File.open(File.join(copy_to, '.htaccess'), 'w') do |f|
116
+ f.write(htaccess)
117
+ end
118
+ end
30
119
  end
31
120
  end
32
121
  end
data/skeleton/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ FIR_ROOT = File.expand_path(File.dirname(__FILE__))
2
+
1
3
  require 'rubygems'
2
4
  require 'fir'
3
5
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - jarrett