woody 0.0.12 → 0.0.13
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/lib/woody/compiler.rb +6 -0
- data/lib/woody/deployer.rb +14 -0
- data/lib/woody/episode.rb +26 -9
- data/lib/woody/generator.rb +14 -0
- data/lib/woody/version.rb +2 -1
- data/lib/woody.rb +11 -5
- metadata +1 -1
data/lib/woody/compiler.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Woody
|
2
|
+
# Handles functions related to compiling the Woody site
|
2
3
|
module Compiler
|
4
|
+
|
5
|
+
# Compiles the Woody site
|
3
6
|
def self.compile()
|
4
7
|
puts "Compiling..."
|
5
8
|
meta = YAML.load_file("content/metadata.yml")
|
@@ -101,6 +104,9 @@ module Woody
|
|
101
104
|
|
102
105
|
private
|
103
106
|
|
107
|
+
# Deletes old files from the site's output directory
|
108
|
+
# @param [Array] touchedfiles specifies which files to keep
|
109
|
+
# @param [String] subdir specifies a subdirectory of output/ to work in (used for recursion)
|
104
110
|
def self.purge_output(touchedfiles, subdir = "")
|
105
111
|
Dir.foreach("output/#{subdir}") do |item|
|
106
112
|
next if item == '.' or item == '..'
|
data/lib/woody/deployer.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Woody
|
2
|
+
# Handles functions relating to deploying the Woody site
|
2
3
|
module Deployer
|
4
|
+
# Deploys the Woody site to S3
|
3
5
|
def self.deploy
|
4
6
|
touchedfiles = Array.new
|
5
7
|
deploy_r touchedfiles
|
@@ -23,6 +25,8 @@ module Woody
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
28
|
+
# Deletes old objects from the S3 bucket
|
29
|
+
# @param [Array] touchedfiles specifies the S3 objects to keep
|
26
30
|
def self.purge_bucket(touchedfiles)
|
27
31
|
bucket = AWS::S3::Bucket.find $bucketname
|
28
32
|
bucket.objects.each do |object|
|
@@ -30,6 +34,10 @@ module Woody
|
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
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
|
33
41
|
def self.filehash(filepath)
|
34
42
|
sha1 = Digest::SHA1.new
|
35
43
|
File.open(filepath) do|file|
|
@@ -43,6 +51,12 @@ module Woody
|
|
43
51
|
return sha1.to_s
|
44
52
|
end
|
45
53
|
|
54
|
+
# Uploads a file to S3
|
55
|
+
# Sets x-amz-meta-hash to hash generated by Woody::Generator.filehash and checks this
|
56
|
+
# before uploading to avoid resending unchanged data
|
57
|
+
# Prints notices to STDOUT
|
58
|
+
# @param [String] objectname specifies the S3 object's key/name
|
59
|
+
# @param [String] filepath specifies the path to the file to upload
|
46
60
|
def self.upload(objectname, filepath)
|
47
61
|
# Generate hash of file
|
48
62
|
hash = filehash filepath
|
data/lib/woody/episode.rb
CHANGED
@@ -1,53 +1,70 @@
|
|
1
1
|
module Woody
|
2
|
+
# Represents an episode of the podcast
|
2
3
|
class Episode
|
4
|
+
# Creates a new Episode object from segment of metadata.yml
|
5
|
+
# @param [String] filename specifies the name of the MP3 file
|
6
|
+
# @param [Hash] meta is the relevant part of metadata.yml
|
7
|
+
# @return [Episode] the new Episode object
|
3
8
|
def self.new_from_meta(filename, meta)
|
4
9
|
return Episode.new(filename, meta['title'], Date.parse(meta['date']), meta['synopsis'], meta['subtitle'], meta['tags'])
|
5
10
|
end
|
6
11
|
|
7
|
-
|
12
|
+
# Creates a new Episode object
|
13
|
+
# @param [String] filename specifies the name of the MP3 file
|
14
|
+
# @param [String] title specifies the episode's title
|
15
|
+
# @param [Date] date specifies the episode's published date
|
16
|
+
# @param [String] synopsis specifies the episode's synopsis
|
17
|
+
# @param [String] subtitle specifies the episode's subtitle
|
18
|
+
# @param [Array] tags specifies the episode's tags - each element is a String
|
19
|
+
# @return [Episode] the new Episode object
|
20
|
+
def initialize(filename, title, date, synopsis, subtitle = nil, tags = [])
|
8
21
|
@filename = filename
|
9
22
|
@title = title
|
10
23
|
@date = date
|
11
24
|
@synopsis = synopsis
|
12
25
|
@subtitle = subtitle
|
13
26
|
@tags = tags
|
14
|
-
@compiledname =
|
15
|
-
|
16
|
-
if @compiledname.nil? or @compiledname.empty?
|
17
|
-
@compiledname = @filename.gsub(/[^0-9A-Za-z .]/, '').gsub(' ', '_')
|
18
|
-
end
|
27
|
+
@compiledname = @filename.gsub(/[^0-9A-Za-z .]/, '').gsub(' ', '_')
|
19
28
|
end
|
20
29
|
|
21
30
|
attr_accessor :filename, :title, :date, :synopsis, :tags, :subtitle, :compiledname
|
22
31
|
|
32
|
+
# @return the episode's page URL where possible, otherwise false
|
23
33
|
def url
|
24
|
-
return "#{$config['urlbase']}#{path}" unless path
|
34
|
+
return "#{$config['urlbase']}#{path}" unless path == false
|
25
35
|
return false
|
26
36
|
end
|
27
37
|
|
38
|
+
# @return the episode's page path where possible, otherwise false
|
28
39
|
def path(leader=true)
|
29
40
|
return "#{leader ? "/" : ""}episode/#{@compiledname[0..-5]}.html" unless @compiledname.nil?
|
30
41
|
return false
|
31
42
|
end
|
32
43
|
|
44
|
+
# @return the episode's media file URL where possible, otherwise false
|
33
45
|
def file_url
|
34
|
-
return "#{$config['urlbase']}#{file_path}" unless file_path
|
46
|
+
return "#{$config['urlbase']}#{file_path}" unless file_path == false
|
35
47
|
return false
|
36
48
|
end
|
37
49
|
|
50
|
+
# @return the episode's media file path where possible, otherwise false
|
38
51
|
def file_path(leader=true)
|
39
52
|
return "#{leader ? "/" : ""}assets/mp3/#{@compiledname}" unless @compiledname.nil?
|
40
53
|
return false
|
41
54
|
end
|
42
55
|
|
56
|
+
# @return [String] a comma separated list of tags, or nil if no tags
|
43
57
|
def keywords
|
44
58
|
@tags.join ', ' unless @tags.nil? or @tags.empty?
|
45
59
|
end
|
46
60
|
|
61
|
+
# @return [Integer] the size of the episodes media file in bytes
|
47
62
|
def size
|
48
63
|
File.size "content/#{filename}"
|
49
64
|
end
|
50
65
|
|
66
|
+
# TODO: fix this!
|
67
|
+
# @return [String] the duration of the media file, formatted as minutes:seconds
|
51
68
|
def duration
|
52
69
|
return @duration unless @duration.nil?
|
53
70
|
length = 0
|
@@ -56,7 +73,7 @@ module Woody
|
|
56
73
|
end
|
57
74
|
length = length.to_i
|
58
75
|
seconds = length % 60
|
59
|
-
minutes = (length / 60).
|
76
|
+
minutes = (length / 60).floor
|
60
77
|
@duration = "#{minutes}:#{seconds}"
|
61
78
|
end
|
62
79
|
|
data/lib/woody/generator.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Woody
|
2
|
+
# Handles functions related to generating Woody sites and updating them and their data stores
|
2
3
|
module Generator
|
4
|
+
# Generates a blank skeleton Woody site
|
5
|
+
# Do not call Woody::init before this!
|
6
|
+
# @param [String] name specifies the relative directory to create the new site in.
|
3
7
|
def self.new_site(name)
|
4
8
|
puts "Creating new site '#{name}'..."
|
5
9
|
if File.directory?(name)
|
@@ -31,6 +35,7 @@ module Woody
|
|
31
35
|
puts "Now, do `cd #{name}` then edit the config file, woody-config.yml."
|
32
36
|
end
|
33
37
|
|
38
|
+
# Replaces the templates in the Woody site with the gem's current default ones
|
34
39
|
def self.update_templates
|
35
40
|
puts "Updating templates..."
|
36
41
|
cpy_t("layout.html", "templates/layout.html")
|
@@ -42,10 +47,19 @@ module Woody
|
|
42
47
|
|
43
48
|
private
|
44
49
|
|
50
|
+
# Path of template directory inside gem
|
51
|
+
$source_root = File.expand_path("../../templates", __FILE__)
|
52
|
+
|
53
|
+
# Creates a directory and its parents if necessary, outputting a notice to STDOUT
|
54
|
+
# @param [String] dir specifies the directory to create
|
45
55
|
def self.cdir_p(dir)
|
46
56
|
puts "Creating directory '#{dir}'"
|
47
57
|
FileUtils.mkdir_p(dir)
|
48
58
|
end
|
59
|
+
|
60
|
+
# Copies a file from inside the gem's template directory, to a location in the current Woody site., outputting a notice to STDOUT.
|
61
|
+
# @param [String] source specificies the source file (inside the gem's internal template directory)
|
62
|
+
# @param [String] destination specidies the destination (inside the Woody site's root directory)
|
49
63
|
def self.cpy_t(source, destination)
|
50
64
|
puts "Creating file '#{destination}'"
|
51
65
|
FileUtils.cp File.join($source_root, source), destination
|
data/lib/woody/version.rb
CHANGED
data/lib/woody.rb
CHANGED
@@ -15,10 +15,10 @@ oldverbosity = $VERBOSE; $VERBOSE = nil # Silence depreciation notice
|
|
15
15
|
require 'mp3info'
|
16
16
|
$VERBOSE = oldverbosity
|
17
17
|
|
18
|
-
|
18
|
+
# Woody podcast static site generator
|
19
19
|
module Woody
|
20
|
-
|
21
|
-
# Load configuration
|
20
|
+
|
21
|
+
# Load configuration and connect to S3
|
22
22
|
def self.init
|
23
23
|
begin
|
24
24
|
$config = YAML.load_file("woody-config.yml")
|
@@ -49,10 +49,16 @@ module Woody
|
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
# Generates HTML hyperlink/anchor tag
|
54
|
+
# @param [String] text specifies text to display for link
|
55
|
+
# @param [String] url specifies URL/path to link to
|
56
|
+
# @return [String] generated HTML anchor tag (hyperlink)
|
57
|
+
def link_to(text, url)
|
58
|
+
return %Q{<a href="#{url}">#{text}</a>}
|
54
59
|
end
|
55
60
|
|
61
|
+
# @return HTML meta generator tag with Woody attribution and version
|
56
62
|
def generator_meta_tag()
|
57
63
|
return %Q{<meta name="generator" content="Woody #{Woody::VERSION}" />}
|
58
64
|
end
|