shopify_theme 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +1,52 @@
1
1
  require 'httparty'
2
2
  module ShopifyTheme
3
- class ShopifyParty
4
- include HTTParty
5
-
6
- def self.asset_list
7
- response = shopify.get("/admin/assets.json")
8
- assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] }
9
- # Remove any .css files if a .css.liquid file exists
10
- assets.reject{|a| assets.include?("#{a}.liquid") }
11
- end
3
+ include HTTParty
12
4
 
13
- def self.get_asset(asset)
14
- response = shopify.get("/admin/assets.json", :query =>{:asset => {:key => asset}})
15
- # HTTParty json parsing is broken?
16
- JSON.parse(response.body)["asset"]
17
- end
5
+ NOOPParser = Proc.new {|data, format| {} }
18
6
 
19
- def self.send_asset(data)
20
- shopify.put("/admin/assets.json", :body =>{:asset => data})
21
- end
7
+ def self.asset_list
8
+ # HTTParty parser chokes on assest listing, have it noop
9
+ # and then use a rel JSON parser.
10
+ response = shopify.get("/admin/assets.json", :parser => NOOPParser)
11
+ assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] }
12
+ # Remove any .css files if a .css.liquid file exists
13
+ assets.reject{|a| assets.include?("#{a}.liquid") }
14
+ end
22
15
 
23
- def self.delete_asset(asset)
24
- shopify.delete("/admin/assets.json", :body =>{:asset => {:key => asset}})
25
- end
16
+ def self.get_asset(asset)
17
+ response = shopify.get("/admin/assets.json", :query =>{:asset => {:key => asset}}, :parser => NOOPParser)
18
+ # HTTParty json parsing is broken?
19
+ JSON.parse(response.body)["asset"]
20
+ end
21
+
22
+ def self.send_asset(data)
23
+ shopify.put("/admin/assets.json", :body =>{:asset => data})
24
+ end
26
25
 
27
- private
28
- def self.shopify
29
- @config = YAML.load(File.read('config.yml'))
30
- basic_auth @config[:api_key], @config[:password]
31
- base_uri "http://#{@config[:store]}"
32
- ShopifyParty
26
+ def self.delete_asset(asset)
27
+ shopify.delete("/admin/assets.json", :body =>{:asset => {:key => asset}})
28
+ end
29
+
30
+ def self.config
31
+ @config ||= YAML.load(File.read('config.yml'))
32
+ end
33
+
34
+ def self.ignore_files
35
+ @ignore_files ||= (config[:ignore_files] || []).compact.collect { |r| Regexp.new(r) }
36
+ end
37
+
38
+ def self.is_binary_data?(string)
39
+ if string.respond_to?(:encoding)
40
+ string.encoding == "US-ASCII"
41
+ else
42
+ ( string.count( "^ -~", "^\r\n" ).fdiv(string.size) > 0.3 || string.index( "\x00" ) ) unless string.empty?
33
43
  end
34
44
  end
45
+
46
+ private
47
+ def self.shopify
48
+ basic_auth config[:api_key], config[:password]
49
+ base_uri "http://#{config[:store]}"
50
+ ShopifyTheme
51
+ end
35
52
  end
@@ -19,14 +19,14 @@ module ShopifyTheme
19
19
 
20
20
  desc "configure API_KEY PASSWORD STORE", "generate a config file for the store to connect to"
21
21
  def configure(api_key=nil, password=nil, store=nil)
22
- config = {:api_key => api_key, :password => password, :store => store}
22
+ config = {:api_key => api_key, :password => password, :store => store, :ignore_files => ["README"]}
23
23
  create_file('config.yml', config.to_yaml)
24
24
  end
25
25
 
26
26
  desc "download FILE", "download the shops current theme assets"
27
27
  method_option :quiet, :type => :boolean, :default => false
28
28
  def download(*keys)
29
- assets = keys.empty? ? ShopifyParty.asset_list : keys
29
+ assets = keys.empty? ? ShopifyTheme.asset_list : keys
30
30
 
31
31
  assets.each do |asset|
32
32
  download_asset(asset)
@@ -44,13 +44,13 @@ module ShopifyTheme
44
44
  end
45
45
  say("Done.", :green) unless options['quiet']
46
46
  end
47
-
47
+
48
48
  desc "replace FILE", "completely replace shop theme assets with local theme assets"
49
49
  method_option :quiet, :type => :boolean, :default => false
50
50
  def replace(*keys)
51
51
  say("Are you sure you want to completely replace your shop theme assets? This is not undoable.", :yellow)
52
52
  if ask("Continue? (Y/N): ") == "Y"
53
- remote_assets = keys.empty? ? ShopifyParty.asset_list : keys
53
+ remote_assets = keys.empty? ? ShopifyTheme.asset_list : keys
54
54
  remote_assets.each do |asset|
55
55
  delete_asset(asset, options['quiet'])
56
56
  end
@@ -84,7 +84,7 @@ module ShopifyTheme
84
84
  end
85
85
  if !options['keep_files']
86
86
  m.delete do |base, relative|
87
- delete_asset(relative, options['quiet'])
87
+ delete_asset(relative, options['quiet']) if local_assets_list.include?(relative)
88
88
  end
89
89
  end
90
90
  end
@@ -93,11 +93,15 @@ module ShopifyTheme
93
93
  private
94
94
 
95
95
  def local_assets_list
96
- Dir.glob(File.join("**", "*")).reject{ |p| File.directory?(p) || IGNORE.include?(p)}
96
+ Dir.glob(File.join("**", "*")).reject do |p|
97
+ File.directory?(p) || IGNORE.include?(p) || ShopifyTheme.ignore_files.any? do |i|
98
+ i =~ p
99
+ end
100
+ end
97
101
  end
98
102
 
99
103
  def download_asset(key)
100
- asset = ShopifyParty.get_asset(key)
104
+ asset = ShopifyTheme.get_asset(key)
101
105
  if asset['value']
102
106
  # For CRLF line endings
103
107
  content = asset['value'].gsub("\r", "")
@@ -111,25 +115,30 @@ module ShopifyTheme
111
115
 
112
116
  def send_asset(asset, quiet=false)
113
117
  data = {:key => asset}
114
- if (content = File.read(asset)).is_binary_data? || BINARY_EXTENSIONS.include?(File.extname(asset).gsub('.',''))
118
+ content = File.read(asset)
119
+ if ShopifyTheme.is_binary_data?(content) || BINARY_EXTENSIONS.include?(File.extname(asset).gsub('.',''))
115
120
  data.merge!(:attachment => Base64.encode64(content))
116
121
  else
117
122
  data.merge!(:value => content)
118
123
  end
119
124
 
120
- if ShopifyParty.send_asset(data).success?
125
+ if (response = ShopifyTheme.send_asset(data)).success?
121
126
  say("Uploaded: #{asset}", :green) unless quiet
122
127
  else
123
- say("Error: Could not upload #{asset}", :red)
128
+ say("Error: Could not upload #{asset}. #{errors_from_response(response)}", :red)
124
129
  end
125
130
  end
126
-
131
+
127
132
  def delete_asset(key, quiet=false)
128
- if ShopifyParty.delete_asset(key).success?
133
+ if (response = ShopifyTheme.delete_asset(key)).success?
129
134
  say("Removed: #{key}", :green) unless quiet
130
135
  else
131
- say("Error: Could not remove #{key}", :red)
136
+ say("Error: Could not remove #{key}. #{errors_from_response(response)}", :red)
132
137
  end
133
- end
138
+ end
139
+
140
+ def errors_from_response(response)
141
+ response.parsed_response ? response.parsed_response["errors"].values.join(", ") : ""
142
+ end
134
143
  end
135
144
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyTheme
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,93 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: shopify_theme
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - John Duff
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-19 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: thor
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2162609340 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 47
30
- segments:
31
- - 0
32
- - 14
33
- - 4
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.14.4
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: httparty
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2162609340
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ requirement: &2162608820 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
45
- hash: 19
46
- segments:
47
- - 0
48
- - 7
49
- - 8
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
50
32
  version: 0.7.8
51
33
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: json
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2162608820
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &2162608420 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
65
44
  type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: fssm
69
45
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2162608420
47
+ - !ruby/object:Gem::Dependency
48
+ name: fssm
49
+ requirement: &2162607940 !ruby/object:Gem::Requirement
71
50
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
79
55
  type: :runtime
80
- version_requirements: *id004
81
- description: Command line tool to help with developing Shopify themes. Provides simple commands to download, upload and delete files from a theme. Also includes the watch command to watch a directory and upload files as they change.
82
- email:
56
+ prerelease: false
57
+ version_requirements: *2162607940
58
+ description: Command line tool to help with developing Shopify themes. Provides simple
59
+ commands to download, upload and delete files from a theme. Also includes the watch
60
+ command to watch a directory and upload files as they change.
61
+ email:
83
62
  - john.duff@shopify.com
84
- executables:
63
+ executables:
85
64
  - theme
86
65
  extensions: []
87
-
88
66
  extra_rdoc_files: []
89
-
90
- files:
67
+ files:
91
68
  - .gitignore
92
69
  - Gemfile
93
70
  - MIT-LICENSE
@@ -98,39 +75,28 @@ files:
98
75
  - lib/shopify_theme/cli.rb
99
76
  - lib/shopify_theme/version.rb
100
77
  - shopify_theme.gemspec
101
- has_rdoc: true
102
78
  homepage: https://github.com/Shopify/shopify_theme
103
79
  licenses: []
104
-
105
80
  post_install_message:
106
81
  rdoc_options: []
107
-
108
- require_paths:
82
+ require_paths:
109
83
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
84
+ required_ruby_version: !ruby/object:Gem::Requirement
111
85
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
119
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
91
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
128
96
  requirements: []
129
-
130
97
  rubyforge_project: shopify_theme
131
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.11
132
99
  signing_key:
133
100
  specification_version: 3
134
101
  summary: Command line tool for developing themes
135
102
  test_files: []
136
-