woody 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -7,6 +7,9 @@ Podcast static site generator
7
7
  To install, run this:
8
8
 
9
9
  $ gem install woody
10
+
11
+ ## To Do List/Roadmap
12
+ [Here, on trello](https://trello.com/board/woody-to-do-list/50c7903cc0e26dc906001fd6)
10
13
 
11
14
  ## Usage
12
15
 
@@ -1,6 +1,7 @@
1
1
  module Woody
2
2
  # Handles functions related to compiling the Woody site
3
3
  module Compiler
4
+ @@touchedfiles = []
4
5
 
5
6
  # Compiles the Woody site
6
7
  def self.compile(options = [])
@@ -9,7 +10,6 @@ module Woody
9
10
 
10
11
  episodes = Array.new
11
12
  filesfound = Array.new
12
- touchedfiles = Array.new
13
13
  Dir.glob('content/*.mp3') do |file|
14
14
  filename = file[8..-1]
15
15
  unless meta == false or meta[filename].nil?
@@ -41,12 +41,11 @@ module Woody
41
41
 
42
42
  # Copy over (TODO: and process) MP3 files
43
43
  episodes.each do |episode|
44
- FileUtils.copy "content/#{episode.filename}", "output/assets/mp3/#{episode.compiledname}"
45
- touchedfiles << "assets/mp3/#{episode.compiledname}"
44
+ copy_file_to_output File.join("content", episode.filename), File.join("assets/mp3", episode.compiledname)
46
45
  end
47
46
 
48
47
  # Copy over assets
49
- copy_assets_r touchedfiles
48
+ copy_assets
50
49
 
51
50
  # Update index.html
52
51
  layout = File.read('templates/layout.html')
@@ -59,8 +58,7 @@ module Woody
59
58
  ep.result(config: $config, episodes: episodes, episode: episode)
60
59
  end
61
60
  end
62
- File.open('output/index.html', 'w') {|f| f.write(index_compiled) }
63
- touchedfiles << 'index.html'
61
+ write_output_file('index.html') {|f| f.write(index_compiled) }
64
62
 
65
63
  # Update episode pages
66
64
  episodes.each do |episode|
@@ -70,15 +68,13 @@ module Woody
70
68
  ep = Erubis::Eruby.new(File.read('templates/episode.html'))
71
69
  ep.result(config: $config, episodes: episodes, episode: episode)
72
70
  end
73
- File.open("output/#{episode.path(false)}", 'w') {|f| f.write(episode_compiled) }
74
- touchedfiles << episode.path(false)
71
+ write_output_file(episode.path) {|f| f.write(episode_compiled) }
75
72
  end
76
73
 
77
74
  # Copy over iTunes.png
78
- if File.exist? "content/iTunes.png"
79
- FileUtils.copy "content/iTunes.png", "output/assets/iTunes.png"
80
- touchedfiles << "assets/iTunes.png"
81
- else
75
+ begin
76
+ copy_file_to_output "content/iTunes.png", "assets/iTunes.png"
77
+ rescue Errno::ENOENT
82
78
  puts "Warning: content/iTunes.png missing!"
83
79
  end
84
80
 
@@ -86,15 +82,15 @@ module Woody
86
82
  itunes = File.read "#{$source_root}/itunes.xml" # Use itunes.xml template in gem, not in site's template folder.
87
83
  itunes = Erubis::Eruby.new(itunes)
88
84
  itunes_compiled = itunes.result(config: $config, episodes: episodes)
89
- File.open("output/itunes.xml", 'w') {|f| f.write(itunes_compiled) }
90
- touchedfiles << "itunes.xml"
85
+ write_output_file("itunes.xml") {|f| f.write(itunes_compiled) }
86
+
91
87
 
92
88
 
93
89
  # Update General RSS
94
90
 
95
91
 
96
92
  # Purge left over files
97
- purge_output(touchedfiles)
93
+ purge_output
98
94
 
99
95
  # Remove all empty directories from the output
100
96
  Dir['output/**/*'].select { |d| File.directory? d }.select { |d| (Dir.entries(d) - %w[ . .. ]).empty? }.each { |d| Dir.rmdir d }
@@ -102,6 +98,23 @@ module Woody
102
98
 
103
99
  private
104
100
 
101
+ # Safely copies files to the output directory
102
+ def self.copy_file_to_output(source, destination)
103
+ d = File.join("output", destination)
104
+ FileUtils.copy source, d
105
+ @@touchedfiles << d
106
+ end
107
+
108
+ # Safely writes files to the output directory
109
+ def self.write_output_file(filename, &block)
110
+ file = File.join("output", filename)
111
+ File.open(file, 'w') do |f|
112
+ yield f
113
+ end
114
+ @@touchedfiles << file
115
+ end
116
+
117
+ # Prompts for metadata for new media files
105
118
  def self.prompt_metadata(meta, episodes, filesfound, filename)
106
119
  puts "Found new media file: #{filename}"
107
120
  if agree("Add metadata for this file? ")
@@ -129,33 +142,23 @@ module Woody
129
142
  end
130
143
  end
131
144
 
132
- # Copies custom assets to output recursively
133
- def self.copy_assets_r(touchedfiles, subdir="")
134
- Dir.foreach("templates/assets/#{subdir}") do |item|
135
- next if item == '.' or item == '..'
136
- unless File.directory?("templates/assets/#{subdir}#{item}")
137
- FileUtils.copy "templates/assets/#{subdir}#{item}", "output/assets/#{subdir}#{item}"
138
- touchedfiles << "assets/#{subdir}#{item}"
139
- else
140
- FileUtils.mkdir_p "output/assets/#{subdir}#{item}"
141
- copy_assets_r touchedfiles, "#{subdir}#{item}/"
142
- end
145
+ # Copies custom assets to output
146
+ def self.copy_assets
147
+ Dir.glob "templates/assets/**/*" do |item|
148
+ next if File.directory? item
149
+ d = item[10..-1] # Cut off "templates/" at beginning
150
+ copy_file_to_output item, d
143
151
  end
144
152
  end
145
153
 
154
+
146
155
  # Deletes old files from the site's output directory
147
- # @param [Array] touchedfiles specifies which files to keep
148
- # @param [String] subdir specifies a subdirectory of output/ to work in (used for recursion)
149
- def self.purge_output(touchedfiles, subdir = "")
150
- Dir.foreach("output/#{subdir}") do |item|
151
- next if item == '.' or item == '..'
152
- p = "#{subdir}#{item}"
153
- begin
154
- File.delete "output/#{subdir}#{item}" unless touchedfiles.include? p
155
- rescue Errno::EISDIR, Errno::EPERM # Rescuing EPERM seems to be necessary on macs, hmm :/
156
- purge_output touchedfiles, "#{p}/"
157
- end
156
+ def self.purge_output
157
+ Dir.glob "output/**/*" do |item|
158
+ next if File.directory? item
159
+ File.delete item unless @@touchedfiles.include? item
158
160
  end
159
161
  end
162
+
160
163
  end
161
164
  end
@@ -1,55 +1,33 @@
1
1
  module Woody
2
2
  # Handles functions relating to deploying the Woody site
3
3
  module Deployer
4
+ @@touchedfiles = []
4
5
  # Deploys the Woody site to S3
5
6
  def self.deploy
6
- touchedfiles = Array.new
7
- deploy_r touchedfiles
7
+ puts "Deploying..."
8
+
9
+ Dir.glob "output/**/*" do |item|
10
+ next if File.directory? item
11
+ name = item[7..-1] # Remove "output/"
12
+ upload name, item
13
+ end
8
14
 
9
15
  # Purge left over files
10
- purge_bucket touchedfiles
16
+ purge_bucket
11
17
  end
12
18
 
13
19
  private
14
20
 
15
- def self.deploy_r(touchedfiles, subdir = "")
16
- puts "Deploying... " if subdir == ""
17
- Dir.foreach("output/#{subdir}") do |item|
18
- next if item == '.' or item == '..'
19
- begin
20
- touchedfiles << "#{subdir}#{item}"
21
- upload("#{subdir}#{item}", "output/#{subdir}#{item}")
22
- rescue Errno::EISDIR
23
- deploy_r touchedfiles, "#{subdir}#{item}/"
24
- end
25
- end
26
- end
27
21
 
28
22
  # Deletes old objects from the S3 bucket
29
23
  # @param [Array] touchedfiles specifies the S3 objects to keep
30
- def self.purge_bucket(touchedfiles)
24
+ def self.purge_bucket
31
25
  bucket = AWS::S3::Bucket.find $bucketname
32
26
  bucket.objects.each do |object|
33
- object.delete unless touchedfiles.include? object.key
27
+ object.delete unless @@touchedfiles.include? object.key
34
28
  end
35
29
  end
36
30
 
37
- # Generates a hash of a file
38
- # Stored in S3 object metadata (x-amz-meta-hash) and used to avoid re-uploading unchanged files
39
- # @param [String] filepath path to file
40
- # @return [String] hash of file
41
- def self.filehash(filepath)
42
- sha1 = Digest::SHA1.new
43
- File.open(filepath) do|file|
44
- buffer = ''
45
- # Read the file 512 bytes at a time
46
- while not file.eof
47
- file.read(512, buffer)
48
- sha1.update(buffer)
49
- end
50
- end
51
- return sha1.to_s
52
- end
53
31
 
54
32
  # Uploads a file to S3
55
33
  # Sets x-amz-meta-hash to hash generated by Woody::Generator.filehash and checks this
@@ -60,7 +38,7 @@ module Woody
60
38
  def self.upload(objectname, filepath)
61
39
  # Generate hash of file
62
40
  hash = filehash filepath
63
-
41
+ @@touchedfiles << objectname
64
42
  # Get hash of version already uploaded, if available.
65
43
  begin
66
44
  object = AWS::S3::S3Object.find objectname, $bucketname
@@ -77,5 +55,24 @@ module Woody
77
55
  puts "#{objectname}: Not uploading, hasn't changed since last time."
78
56
  end
79
57
  end
58
+
59
+
60
+ # Generates a hash of a file
61
+ # Stored in S3 object metadata (x-amz-meta-hash) and used to avoid re-uploading unchanged files
62
+ # @param [String] filepath path to file
63
+ # @return [String] hash of file
64
+ def self.filehash(filepath)
65
+ sha1 = Digest::SHA1.new
66
+ File.open(filepath) do|file|
67
+ buffer = ''
68
+ # Read the file 512 bytes at a time
69
+ while not file.eof
70
+ file.read(512, buffer)
71
+ sha1.update(buffer)
72
+ end
73
+ end
74
+ return sha1.to_s
75
+ end
76
+
80
77
  end
81
78
  end
data/lib/woody/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Woody
2
2
  # Specifies Woody gem version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woody
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-10 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis