Class: Nimbu::Command::Themes
Overview
working with themes (upload / download)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#download ⇒ Object
download.
-
#index ⇒ Object
server.
-
#list ⇒ Object
list.
-
#push ⇒ Object
download.
Methods inherited from Base
#app, #initialize, namespace, #nimbu
Methods included from Helpers
#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, disable_error_capture, #display, #display_header, #display_object, #display_row, #display_table, enable_error_capture, #error, #error_with_failure, extended, extended_into, #fail, #format_bytes, #format_date, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #longest, #output, #output_with_arrow, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #status, #string_distance, #time_ago, #truncate, #with_tty
Constructor Details
This class inherits a constructor from Nimbu::Command::Base
Instance Method Details
#download ⇒ Object
download
download all layouts, templates and assets
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nimbu/command/themes.rb', line 53 def download input = args.shift.downcase rescue nil if !input.to_s.strip.empty? theme = input.to_s.strip else theme = Nimbu::Auth.theme end display "Downloading layouts, templates and assets for '#{theme}':" contents = json_decode(nimbu.show_theme_contents(theme)) contents["layouts"].each do |asset| print " - layouts/#{asset["name"]}" data = json_decode(nimbu.fetch_theme_layout(theme,asset["id"])) filename = File.join(Dir.pwd,"layouts",asset["name"]) FileUtils.mkdir_p(File.dirname(filename)) File.open(filename, 'w') do |file| file.puts(data["code"]) end print " (ok)\n" end contents["templates"].each do |asset| print " - templates/#{asset["name"]}" data = json_decode(nimbu.fetch_theme_template(theme,asset["id"])) filename = File.join(Dir.pwd,"templates",asset["name"]) FileUtils.mkdir_p(File.dirname(filename)) File.open(filename, 'w') do |file| file.puts(data["code"]) end print " (ok)\n" end end |
#index ⇒ Object
server
list available commands or display help for a specific command
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nimbu/command/themes.rb', line 11 def index themes = json_decode(nimbu.list_themes) if themes.any? puts "You have following themes for this website:" themes.each do |theme| puts " - #{theme['theme']['name']} (#{theme['theme']['id']})" end else puts "Hm. You seem to have no themes. Is that normal?" end puts "" puts "Currently this directory is configured for '#{Nimbu::Auth.theme}'" end |
#list ⇒ Object
list
list all layouts, templates and assets
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nimbu/command/themes.rb', line 29 def list input = args.shift.downcase rescue nil if !input.to_s.strip.empty? theme = input.to_s.strip else theme = Nimbu::Auth.theme end display "Showing layouts, templates and assets for '#{theme}':" contents = json_decode(nimbu.show_theme_contents(theme)) contents["layouts"].each do |l| display " - layouts/#{l["name"]}" end unless contents["layouts"].nil? contents["templates"].each do |t| display " - templates/#{t["name"]}" end unless contents["templates"].nil? contents["assets"].each do |a| display " - #{a["folder"]}/#{a["name"]}" end unless contents["assets"].nil? end |
#push ⇒ Object
download
download all layouts, templates and assets
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/nimbu/command/themes.rb', line 91 def push simulate = args.include?("--dry-run") || args.include?("-d") liquid_only = args.include?("--liquid-only") || args.include?("--liquid") css_only = args.include?("--css-only") || args.include?("--css") js_only = args.include?("--js-only") || args.include?("-js") # if !input.to_s.strip.empty? # theme = input.to_s.strip # else # end theme = Nimbu::Auth.theme display "Pushing layouts, templates and assets for '#{theme}' to the server:" layouts_glob = Dir.glob("#{Dir.pwd}/layouts/**/*.liquid") layouts_files = layouts_glob.map {|dir| dir.gsub("#{Dir.pwd}/layouts/","")} templates_glob = Dir.glob("#{Dir.pwd}/templates/**/*.liquid") templates_files = templates_glob.map {|dir| dir.gsub("#{Dir.pwd}/templates/","")} if !(css_only || js_only) print "\nLayouts:\n" layouts_files.each do |layout| file = "#{Dir.pwd}/layouts/#{layout}" next if File.directory?(file) print " - layouts/#{layout}" nimbu.upload_layout(theme, layout, IO.read(file)) print " (ok)\n" end print "\nTemplates:\n" templates_files.each do |template| file = "#{Dir.pwd}/templates/#{template}" next if File.directory?(file) print " - templates/#{template}" nimbu.upload_template(theme, template, IO.read(file)) print " (ok)\n" end end if !liquid_only css_glob = Dir.glob("#{Dir.pwd}/stylesheets/**/*.css") css_files = css_glob.map {|dir| dir.gsub("#{Dir.pwd}/stylesheets/","")} if !js_only print "\nStylesheet:\n" css_files.each do |css| file = "#{Dir.pwd}/stylesheets/#{css}" next if File.directory?(file) || (!anyFileWithWord?(layouts_glob,css) && !anyFileWithWord?(templates_glob,css)) nimbu.upload_asset(theme, "stylesheets/#{css}", File.open(file)) print " - stylesheets/#{css}" print " (ok)\n" end end js_glob = Dir.glob("#{Dir.pwd}/javascripts/**/*.js") js_files = js_glob.map {|dir| dir.gsub("#{Dir.pwd}/javascripts/","")} if !css_only print "\nJavascripts:\n" js_files.each do |js| file = "#{Dir.pwd}/javascripts/#{js}" next if File.directory?(file) || (!anyFileWithWord?(layouts_glob,js) && !anyFileWithWord?(templates_glob,js)) nimbu.upload_asset(theme, "javascripts/#{js}", File.open(file)) print " - javascripts/#{js}" print " (ok)\n" end end image_files = Dir.glob("#{Dir.pwd}/images/**/*").map {|dir| dir.gsub("#{Dir.pwd}/images/","")} if !(css_only || js_only) print "\nImages:\n" image_files.each do |image| file = "#{Dir.pwd}/images/#{image}" next if File.directory?(file) || (!anyFileWithWord?(css_glob,image) && !anyFileWithWord?(js_glob,image) && !anyFileWithWord?(layouts_glob,image) && !anyFileWithWord?(templates_glob,image)) nimbu.upload_asset(theme, "images/#{image}", File.open(file)) print " - images/#{image}" print " (ok)\n" end end end end |