scharfie-bones 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +5 -1
- data/bones.gemspec +1 -1
- data/lib/cache.rb +23 -8
- data/lib/tasks/bones.rb +11 -1
- metadata +1 -1
data/README
CHANGED
data/bones.gemspec
CHANGED
data/lib/cache.rb
CHANGED
@@ -7,12 +7,13 @@ require 'ostruct'
|
|
7
7
|
class Bones
|
8
8
|
class Cache
|
9
9
|
class Options
|
10
|
-
attr_accessor :base, :versioned, :release, :destination
|
10
|
+
attr_accessor :base, :versioned, :release, :destination, :noop
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
super
|
14
14
|
self.base = '' # Base URL is empty
|
15
15
|
self.release = nil
|
16
|
+
self.noop = false
|
16
17
|
end
|
17
18
|
|
18
19
|
def merge(options={})
|
@@ -38,6 +39,10 @@ class Bones
|
|
38
39
|
o.on('--base PATH', "Change the base URL path") do |path|
|
39
40
|
options.base = path # Bones.base = path
|
40
41
|
end
|
42
|
+
|
43
|
+
o.on('--noop', "Do not write any files") do
|
44
|
+
options.noop = true
|
45
|
+
end
|
41
46
|
|
42
47
|
o.on_tail("-h", "--help", "Show this message") do
|
43
48
|
puts o; exit
|
@@ -101,11 +106,15 @@ class Bones
|
|
101
106
|
|
102
107
|
# Process each page
|
103
108
|
Dir.chdir(ROOT) do
|
109
|
+
puts "** Note: No files/directories will be modified (noop flag)" if options.noop
|
104
110
|
puts "** Writing to: #{options.destination}"
|
105
111
|
puts "** Using base: #{options.base}" unless options.base.blank?
|
106
112
|
|
107
|
-
Bones.pages
|
108
|
-
|
113
|
+
pages = Bones.pages
|
114
|
+
total = pages.length
|
115
|
+
pages.each_with_index do |page, index|
|
116
|
+
print "\r %-70s (%4d/%4d)" % [[version, page].compact.join('/') + '.html', index + 1, total]
|
117
|
+
$stdout.flush
|
109
118
|
template = Bones::Template.new(page)
|
110
119
|
template.request = generate_mock_request(:path_info => page)
|
111
120
|
result = template.compile
|
@@ -114,17 +123,23 @@ class Bones
|
|
114
123
|
property =~ /url/ ? 'url(%s%s)' % [url, params] : '%s="%s%s"' % [property, url, params]
|
115
124
|
end
|
116
125
|
path = options.destination / page + '.html'
|
117
|
-
|
118
|
-
|
126
|
+
|
127
|
+
unless options.noop
|
128
|
+
FileUtils.mkdir_p(File.dirname(path))
|
129
|
+
File.open(path, 'w') { |f| f.write(result) }
|
130
|
+
end
|
119
131
|
end
|
132
|
+
|
133
|
+
puts "\n"
|
120
134
|
|
121
135
|
if options.release?
|
122
136
|
puts "** Copying public files"
|
123
|
-
options.release.copy_public_directories
|
137
|
+
options.release.copy_public_directories unless options.noop
|
124
138
|
end
|
125
139
|
|
126
|
-
puts "** Cached to: #{options.destination}"
|
127
|
-
puts "** Using base: #{options.base}" unless options.base.blank?
|
140
|
+
# puts "** Cached to: #{options.destination}"
|
141
|
+
# puts "** Using base: #{options.base}" unless options.base.blank?
|
142
|
+
# puts "** Note: No files/directories were modified (noop flag)" if options.noop
|
128
143
|
end
|
129
144
|
|
130
145
|
puts "** Done."
|
data/lib/tasks/bones.rb
CHANGED
@@ -13,10 +13,20 @@ desc "Cache page templates for redistribution (non-versioned)"
|
|
13
13
|
task :cache => 'cache:simple'
|
14
14
|
|
15
15
|
namespace :cache do
|
16
|
+
def destination_from_environment
|
17
|
+
%w(DESTINATION DEST).each do |k|
|
18
|
+
return ENV[k] unless ENV[k].blank?
|
19
|
+
end
|
20
|
+
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
16
24
|
def generate_options_from_environment(extra={})
|
17
25
|
returning Bones::Cache::Options.new do |options|
|
26
|
+
destination = destination_from_environment
|
18
27
|
options.base = ENV['BASE'] unless ENV['BASE'].blank?
|
19
|
-
options.destination =
|
28
|
+
options.destination = destination unless destination.blank?
|
29
|
+
options.noop = true if ENV['NOOP']
|
20
30
|
options.merge extra
|
21
31
|
end
|
22
32
|
end
|