fir 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  FIR_ROOT = File.expand_path(File.dirname(__FILE__))
2
2
 
3
+ #$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib')) # Enable this to run against the code in the parent directory instead of the intalled gem
3
4
  require 'rubygems'
4
5
  require 'fir'
5
6
 
@@ -11,7 +11,7 @@
11
11
  </title>
12
12
  <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
13
13
  <% if @description and !@description.empty? %>
14
- <meta name="description" content="<%= h @page_description %>"/>
14
+ <meta name="description" content="<%= h @description %>"/>
15
15
  <% end %>
16
16
 
17
17
  <!--[if !IE 6]><!-->
@@ -7,10 +7,6 @@ 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
14
10
  #use ::Rack::Reloader # Only when developing the Fir gem
15
11
  use ::Rack::ContentLength
16
12
  use ::Fir::Static
@@ -28,24 +28,14 @@ module Fir
28
28
  end
29
29
  end
30
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]'
31
+ 'Usage: rake export dir=path_to_export_to'
32
32
  task :export do
33
33
  require 'fileutils'
34
34
 
35
35
  if !ENV.has_key?('dir') or ENV['dir'].empty?
36
- raise(ArgumentError, 'Usage: rake export dir=path_to_export_to [port=3000]')
36
+ raise(ArgumentError, 'Usage: rake export dir=path_to_export_to')
37
37
  end
38
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
39
  page_config = YAML.load(File.read(File.join(FIR_ROOT, 'pages.yml')))
50
40
  path_mappings = page_config.inject({}) do |mappings, (page, configs)|
51
41
  mappings[configs['path']] = page if configs['path']
@@ -64,36 +54,18 @@ module Fir
64
54
  result
65
55
  end + path_mappings.keys
66
56
 
67
- puts 'Getting each page to generate the cache...'
57
+ puts 'Iniitalizing Fir site...'
68
58
 
59
+ Fir.config.force_caching = true
60
+ require File.expand_path(File.join(FIR_ROOT, 'config.rb'))
61
+ builder = Rack::Builder.new(&Fir.boot_proc)
62
+
63
+ puts 'Getting each page to generate the cache...'
69
64
  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
65
+ puts ' GET ' + path
66
+ builder.call({'PATH_INFO' => '/' + path})
91
67
  end
92
68
 
93
- server_pid = File.read(pid_file).to_i
94
- Process.kill('SIGINT', server_pid)
95
- File.delete(pid_file)
96
-
97
69
  copy_from = File.join(FIR_ROOT, 'public', '.')
98
70
  copy_to = ENV['dir']
99
71
  unless File.exists?(copy_to)
@@ -11,6 +11,8 @@ module Fir
11
11
  def self.config
12
12
  @config ||= OpenStruct.new
13
13
  yield @config if block_given?
14
+ # force_caching allows the export task to turn caching on even if it's set to off in config.rb
15
+ @config.perform_caching = true if @config.force_caching
14
16
  # Default configs go here
15
17
  @config.perform_caching ||= false
16
18
  @config.relative_url_root ||= ''
@@ -11,7 +11,7 @@
11
11
  </title>
12
12
  <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
13
13
  <% if @description and !@description.empty? %>
14
- <meta name="description" content="<%= h @page_description %>"/>
14
+ <meta name="description" content="<%= h @description %>"/>
15
15
  <% end %>
16
16
 
17
17
  <!--[if !IE 6]><!-->
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - jarrett
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-01 00:00:00 -06:00
17
+ date: 2010-03-02 00:00:00 -06:00
18
18
  default_executable: fir
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency