Sha256: b7f470f72686f417ccd54fb3b8863cfd5a8f14fccced38a1767796f7c99136b7
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
class DiscourseTheme::Watcher def initialize(dir:, uploader:) @dir = dir @uploader = uploader end def watch listener = Listen.to(@dir) do |modified, added, removed| if modified.length == 1 && added.length == 0 && removed.length == 0 && (resolved = resolve_file(modified[0])) target, name, type_id = resolved print "Updating #{target} #{name}: " @uploader.upload_theme_field( target: target, name: name, value: File.read(modified[0]), type_id: type_id ) else print "Full re-sync is required, re-uploading theme: " @uploader.upload_full_theme end end listener.start sleep end protected def resolve_file(path) dir_len = File.expand_path(@dir).length name = File.expand_path(path)[dir_len + 1..-1] target, file = name.split("/") if ["common", "desktop", "mobile"].include?(target) if file = "#{target}.scss" # a CSS file return [target, "scss", 1] end end nil end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
discourse_theme-0.1.1 | lib/discourse_theme/watcher.rb |
discourse_theme-0.1.0 | lib/discourse_theme/watcher.rb |