Class: Yuzu::Core::Updater
Overview
Updater is the primary mechanism to update a website and filter for the files that need updating.
Instance Method Summary collapse
- #done ⇒ Object
-
#initialize(uploader, config) ⇒ Updater
constructor
A new instance of Updater.
- #update_all ⇒ Object
- #update_by_filter(proc_filter) ⇒ Object
-
#update_file(website_file) ⇒ Object
Update a single WebsiteFile.
- #update_text ⇒ Object
-
#update_these(files_to_update = []) ⇒ Object
Update a particular list of files.
- #upload_all_assets ⇒ Object
- #upload_all_css ⇒ Object
- #upload_all_images ⇒ Object
- #upload_all_resources ⇒ Object
- #upload_new_images(known_images = []) ⇒ Object
Constructor Details
#initialize(uploader, config) ⇒ Updater
Returns a new instance of Updater.
16 17 18 19 20 21 22 23 |
# File 'lib/yuzu/core/updater.rb', line 16 def initialize(uploader, config) @uploader = uploader @config = config @siteroot = SiteRoot.new(@config) $stderr.puts "Updater initialized..." if @config.verbose? end |
Instance Method Details
#done ⇒ Object
119 120 121 |
# File 'lib/yuzu/core/updater.rb', line 119 def done @uploader.close! unless @uploader.nil? end |
#update_all ⇒ Object
25 26 27 28 29 30 |
# File 'lib/yuzu/core/updater.rb', line 25 def update_all $stderr.puts "Updating all..." if @config.verbose? filter = proc {|c| (c.processable? or c.resource? or c.image? or c.asset?) and not c.hidden?} update_by_filter(filter) end |
#update_by_filter(proc_filter) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yuzu/core/updater.rb', line 64 def update_by_filter(proc_filter) updated = [] visit = Visitor.new(proc_filter) visit.traverse(@siteroot) do |file| update_file(file) updated.push(file) end updated end |
#update_file(website_file) ⇒ Object
Update a single WebsiteFile. This effectively initiates the uploader to publish the file to the destination specified by the currently selected service.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/yuzu/core/updater.rb', line 78 def update_file(website_file) $stderr.puts "#{BOLD}#{WHITE}Updating #{website_file}#{ENDC}#{ENDC}" if @config.verbose? if website_file.processable? @uploader.upload(website_file.remote_path, website_file.html_contents) elsif website_file.resource? or website_file.image? or website_file.asset? f = File.open(website_file.path.absolute, "r") @uploader.upload(website_file.remote_path, f) f.close else $stderr.puts "Can't update #{website_file}." if @config.verbose? end end |
#update_text ⇒ Object
32 33 34 35 36 37 |
# File 'lib/yuzu/core/updater.rb', line 32 def update_text $stderr.puts "Updating text files..." if @config.verbose? filter = proc {|c| c.processable? and not c.hidden?} update_by_filter(filter) end |
#update_these(files_to_update = []) ⇒ Object
Update a particular list of files. This is relatively expensive as it requires searching through the file tree, but it should work well for a few files.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/yuzu/core/updater.rb', line 100 def update_these(files_to_update=[]) if files_to_update.empty? update_all return end $stderr.puts "Updating files..." if @config.verbose? files_to_update.each do |relative_path| p = Helpers::Path.new(relative_path) website_file = @siteroot.find_file_by_path(p) if not website_file.nil? update_file(website_file) else $stderr.puts "Couldn't find a WebsiteFile for #{p}" if @config.verbose? end end end |
#upload_all_assets ⇒ Object
49 50 51 52 |
# File 'lib/yuzu/core/updater.rb', line 49 def upload_all_assets filter = proc {|c| c.asset? and not c.hidden?} update_by_filter(filter) end |
#upload_all_css ⇒ Object
59 60 61 62 |
# File 'lib/yuzu/core/updater.rb', line 59 def upload_all_css filter = proc {|c| c.path.extension == ".css" and not c.hidden?} update_by_filter(filter) end |
#upload_all_images ⇒ Object
44 45 46 47 |
# File 'lib/yuzu/core/updater.rb', line 44 def upload_all_images filter = proc {|c| c.image? and not c.hidden?} update_by_filter(filter) end |
#upload_all_resources ⇒ Object
54 55 56 57 |
# File 'lib/yuzu/core/updater.rb', line 54 def upload_all_resources filter = proc {|c| c.resource? and not c.hidden?} update_by_filter(filter) end |
#upload_new_images(known_images = []) ⇒ Object
39 40 41 42 |
# File 'lib/yuzu/core/updater.rb', line 39 def upload_new_images(known_images=[]) filter = proc {|c| c.image? and not c.hidden? and not known_images.include?(c)} update_by_filter(filter) end |