Class: Broadway::Runner
- Inherits:
-
Object
- Object
- Broadway::Runner
- Defined in:
- lib/broadway/runner.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#site ⇒ Object
Returns the value of attribute site.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #error?(response, path, whiny = true) ⇒ Boolean
-
#initialize(site) ⇒ Runner
constructor
A new instance of Runner.
- #run(&block) ⇒ Object
Constructor Details
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/broadway/runner.rb', line 5 def content @content end |
#site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/broadway/runner.rb', line 5 def site @site end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/broadway/runner.rb', line 5 def url @url end |
Instance Method Details
#error?(response, path, whiny = true) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/broadway/runner.rb', line 38 def error?(response, path, whiny = true) if !response.is_a?(Net::HTTPSuccess) raise if whiny puts "Error at '#{path}': #{response.to_s}" return true end false end |
#run(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/broadway/runner.rb', line 13 def run(&block) begin Net::HTTP.start(url.host, url.port) do |http| self.content.each do |item| response = http.get(item.url) # if the file doesn't exist or is not rendered correctly next if error?(response, item.url, false) write_dir = File.(File.join(site.config[:destination], item.dir)) name = File.join(write_dir, "index.html") FileUtils.mkdir_p(write_dir) text = "" text << "---\n" text << "categories: #{item.categories.sort.join(" ")}\n" text << "---\n" text << response.body yield text if block_given? File.write(name, text) end end rescue Exception => e puts e.inspect raise "Make sure you've started the server, run: 'ruby app.rb'" end end |