Class: Nimbu::Command::Themes
Overview
working with themes (upload / download)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#diff ⇒ Object
themes.
-
#index ⇒ Object
themes.
-
#list ⇒ Object
themes:list.
-
#push ⇒ Object
themes:push.
Methods inherited from Base
#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, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #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, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty
Methods included from Helpers::System
#browser_launcher, #command?, #osx?, #tmp_dir, #which, #windows?
Constructor Details
This class inherits a constructor from Nimbu::Command::Base
Instance Method Details
#diff ⇒ Object
themes
list available commands or display help for a specific command
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nimbu/command/themes.rb', line 72 def diff require 'diffy' @diff = {} input = args.shift.downcase rescue nil theme = if !input.to_s.strip.empty? input.to_s.strip else Nimbu::Auth.theme end display "\nShowing differences between local and server\nlayouts, templates, snippets and assets for '#{theme.green.bold}':" json = nimbu.themes(:subdomain => Nimbu::Auth.site).get(theme) check_differences(json, theme, "layouts", "templates", "snippets") end |
#index ⇒ Object
themes
list available commands or display help for a specific command
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nimbu/command/themes.rb', line 12 def index themes = nimbu.themes(:subdomain => Nimbu::Auth.site).list if themes.any? display "\nYou have following themes for this website:" themes.each do |theme| puts " - #{theme.name.bold} (#{theme.short})" 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.red.bold}'" end |
#list ⇒ Object
themes:list
list all layouts, templates and assets
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nimbu/command/themes.rb', line 30 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 "\nShowing layouts, templates, snippets and assets for '#{theme.red.bold}':" contents = nimbu.themes(:subdomain => Nimbu::Auth.site).get(theme) if contents["layouts"].any? display "\nLayouts:".bold contents["layouts"].each do |l| display " - layouts/#{l["name"]}" end end if contents["templates"].any? display "\nTemplates:".bold contents["templates"].each do |t| display " - templates/#{t["name"]}" end end if contents["snippets"].any? display "\nSnippets:".bold contents["snippets"].each do |s| display " - snippets/#{s["name"]}" end end if contents["assets"].any? display "\nAssets:".bold contents["assets"].each do |a| display " - #{a["folder"]}/#{a["name"]}" end end end |
#push ⇒ Object
themes:push
push all layouts, templates and assets –liquid, –liquid-only # only push template code –css, –css-only # only push template code –js, –js-only # only push template code –images-only # only push new images
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/nimbu/command/themes.rb', line 94 def push liquid_only = [:liquid] css_only = [:css] js_only = [:js] images_only = [:images_only] # 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/","")} snippets_glob = Dir.glob("#{Dir.pwd}/snippets/**/*.liquid") snippets_files = snippets_glob.map {|dir| dir.gsub("#{Dir.pwd}/snippets/","")} if !(css_only || js_only || images_only) print "\nLayouts:\n" layouts_files.each do |layout| file = "#{Dir.pwd}/layouts/#{layout}" next if File.directory?(file) print " - layouts/#{layout}" nimbu.themes(:subdomain => Nimbu::Auth.site).layouts(:theme_id => theme).create({:name => layout, :content => IO.read(file).force_encoding('UTF-8')}) 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.themes(:subdomain => Nimbu::Auth.site).templates(:theme_id => theme).create({:name => template, :content => IO.read(file).force_encoding('UTF-8')}) print " (ok)\n" end print "\nSnippets:\n" snippets_files.each do |snippet| file = "#{Dir.pwd}/snippets/#{snippet}" next if File.directory?(file) print " - snippets/#{snippet}" nimbu.themes(:subdomain => Nimbu::Auth.site).snippets(:theme_id => theme).create({:name => snippet, :content => IO.read(file).force_encoding('UTF-8')}) 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 || images_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) && !anyFileWithWord?(snippets_glob,css)) io = Faraday::UploadIO.new(File.open(file), 'application/octet-stream', File.basename(file)) nimbu.themes(:subdomain => Nimbu::Auth.site).assets(:theme_id => theme).create({:name => "stylesheets/#{css}", :file => io}) 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 || images_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) && !anyFileWithWord?(snippets_glob,js)) io = Faraday::UploadIO.new(File.open(file), 'application/octet-stream', File.basename(file)) nimbu.themes(:subdomain => Nimbu::Auth.site).assets(:theme_id => theme).create({:name => "javascripts/#{js}", :file => io}) 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) && !anyFileWithWord?(snippets_glob,image)) io = Faraday::UploadIO.new(File.open(file), 'application/octet-stream', File.basename(file)) nimbu.themes(:subdomain => Nimbu::Auth.site).assets(:theme_id => theme).create({:name => "images/#{image}", :file => io}) print " - images/#{image}" print " (ok)\n" end end font_files = Dir.glob("#{Dir.pwd}/fonts/**/*").map {|dir| dir.gsub("#{Dir.pwd}/fonts/","")} rescue [] if !(css_only || js_only) print "\nFonts:\n" font_files.each do |font| file = "#{Dir.pwd}/fonts/#{font}" next if File.directory?(file) || (!anyFileWithWord?(css_glob,font) && !anyFileWithWord?(js_glob,font) && !anyFileWithWord?(layouts_glob,font) && !anyFileWithWord?(templates_glob,font) && !anyFileWithWord?(snippets_glob,font)) io = Faraday::UploadIO.new(File.open(file), 'application/octet-stream', File.basename(file)) nimbu.themes(:subdomain => Nimbu::Auth.site).assets(:theme_id => theme).create({:name => "fonts/#{font}", :file => io}) print " - fonts/#{font}" print " (ok)\n" end end end end |