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.
Files changed (5) hide show
  1. data/README +5 -1
  2. data/bones.gemspec +1 -1
  3. data/lib/cache.rb +23 -8
  4. data/lib/tasks/bones.rb +11 -1
  5. metadata +1 -1
data/README CHANGED
@@ -50,4 +50,8 @@ Advanced features:
50
50
 
51
51
  - Use custom cache directory
52
52
 
53
- rake cache DESTINATION=/some/other/path
53
+ rake cache DESTINATION=/some/other/path
54
+
55
+ - Dry-run (noop) for testing settings without creating any files
56
+
57
+ rake cache NOOP=true
data/bones.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "bones"
3
- s.version = "0.1.4"
3
+ s.version = "0.1.5"
4
4
  s.date = "2009-02-04"
5
5
  s.authors = ["Chris Scharf", "Ryan Heath"]
6
6
  s.email = "scharfie@gmail.com"
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.each do |page|
108
- puts "** Generating #{[version, page].compact.join('/')}.html"
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
- FileUtils.mkdir_p(File.dirname(path))
118
- File.open(path, 'w') { |f| f.write(result) }
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 = ENV['DESTINATION'] unless ENV['DESTINATION'].blank?
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scharfie-bones
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Scharf