shopify_theme 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09f5dc9eab1ad2d39124fc370b4e84047adf062a
4
+ data.tar.gz: 1119a4e02bff799bf80a7d91462b5c34bc68d1d6
5
+ SHA512:
6
+ metadata.gz: 52d308c07b4d8c061c6971457eabb519fcaa87c205fefd27b2360d2fc3bcf5b4e1669ca981e897b3d493e4d149f2ac907896b6c37f98fb408d4387e02af88e69
7
+ data.tar.gz: 6fd1f422f49cc2ab4a129c1d5d6fc33eae3d6743a036ba02453e900bafd1e4f6de196cb3fcf9650d59d8f97094ebd540b5b83e43c2cbf2a447b7532d68518387
data/README.md CHANGED
@@ -1,19 +1,36 @@
1
1
  # Edit your Shopify theme locally
2
2
 
3
- The Shopify theme gem is a command line tool that lets you make live changes to your published theme.
3
+ The Shopify theme gem is a command line tool that lets you make live changes to themes on your Shopify store. If the command line is scary, check out the [Desktop Theme Editor app](http://apps.shopify.com/desktop-theme-editor).
4
4
 
5
5
  It will watch your local folders for any changes in your theme (including adding and removing files) and will update your .myshopify.com store to the latest changes.
6
6
 
7
+ ![Shopify theme gem](https://dl.dropboxusercontent.com/u/669627/terminalreadme.png)
8
+
9
+ You do not need to make changes to your default theme. You can leverage the theme preview feature of Shopify
10
+ that allows you to view what an unpublished theme looks like on your Shopify store. This means you don't need to
11
+ sign up for extra accounts and keep your shop up to date. You will however have a blue bar that shows up that you can
12
+ remove via the web inspector in Chrome or Safari.
13
+
7
14
  # Requirements
8
15
 
9
- Ruby 1.9
16
+ This gem works with OS X or Windows with Ruby 1.9.
17
+
18
+ First time installing Ruby on windows? Try [Rubyinstaller](http://http://rubyinstaller.org/).
10
19
 
11
20
  # Installation
12
21
 
22
+ To install the shopify_theme gem use 'gem install' (you might have use 'sudo gem install')
23
+
13
24
  ```
14
25
  gem install shopify_theme [optional_theme_id]
15
26
  ```
16
27
 
28
+ to update to the latest version
29
+
30
+ ```
31
+ gem update shopify_theme
32
+ ```
33
+
17
34
  # Usage
18
35
 
19
36
  Generate the config file. Go get a valid api_key and password for your store head to `https://[your store].myshopify.com/admin/apps/private` and generate a private application. Default it adds the main theme, if you want to edit one of your other themes, add the `theme_id`.
@@ -75,15 +92,22 @@ theme open
75
92
 
76
93
  # Common Problems
77
94
 
78
- ### When trying to run `theme watch` on Windows the application crashes with a gross stack trace
79
-
80
- The gem doesn't install one of the dependencies you need in order to use this gem correctly on Windows. You
81
- can get around this by either executing `gem install wdm` or by creating a Gemfile in your theme project such
82
- as the following:
95
+ ## How do I edit a theme that isn't my shops main theme?
83
96
 
84
- ```ruby
85
- source "http://rubygems.org" # I could not validate the rubygems SSL certificate on Windows
97
+ This can be done by setting the `theme_id` field in `config.yml` which was created when you
98
+ ran `theme configure`. Your file should look like the following:
86
99
 
87
- gem "wdm"
88
- gem "shopify_theme"
100
+ ```yaml
101
+ ---
102
+ :api_key: 7a8da86d3dd730b67a357dedabaac5d6
103
+ :password: 552338ce0d3aba7fc501dcf99bc57a81
104
+ :store: little-plastics.myshopify.com
105
+ :theme_id: 0987654321
89
106
  ```
107
+
108
+ ## Where can I find my Theme Id?
109
+
110
+ Currently the best way to find the id of the theme you want to edit is to go to the theme in your
111
+ shops admin and grab it from the url.
112
+
113
+ ![themes/THEME_ID/settings](doc/how_to_find_theme_id.png)
@@ -5,14 +5,15 @@ module ShopifyTheme
5
5
  @@total_api_calls = 40
6
6
 
7
7
  NOOPParser = Proc.new {|data, format| {} }
8
- TIMER_RESET = 5 * 60 + 5
9
- PERMIT_LOWER_LIMIT = 10
8
+ TIMER_RESET = 10
9
+ PERMIT_LOWER_LIMIT = 3
10
10
 
11
11
  def self.test?
12
12
  ENV['test']
13
13
  end
14
14
 
15
15
  def self.manage_timer(response)
16
+ return unless response.headers['x-shopify-shop-api-call-limit']
16
17
  @@current_api_call_count, @@total_api_calls = response.headers['x-shopify-shop-api-call-limit'].split('/')
17
18
  @@current_timer = Time.now if @current_timer.nil?
18
19
  end
@@ -40,6 +41,10 @@ module ShopifyTheme
40
41
  end
41
42
  end
42
43
 
44
+ def self.api_usage
45
+ "[API Limit: #{@@current_api_call_count || "??"}/#{@@total_api_calls || "??"}]"
46
+ end
47
+
43
48
 
44
49
  def self.asset_list
45
50
  # HTTParty parser chokes on assest listing, have it noop
@@ -38,12 +38,17 @@ module ShopifyTheme
38
38
 
39
39
  desc "download FILE", "download the shops current theme assets"
40
40
  method_option :quiet, :type => :boolean, :default => false
41
+ method_option :exclude
41
42
  def download(*keys)
42
43
  assets = keys.empty? ? ShopifyTheme.asset_list : keys
43
44
 
45
+ if options['exclude']
46
+ assets = assets.delete_if { |asset| asset =~ Regexp.new(options['exclude']) }
47
+ end
48
+
44
49
  assets.each do |asset|
45
50
  download_asset(asset)
46
- say("Downloaded: #{asset}", :green) unless options['quiet']
51
+ say("#{ShopifyTheme.api_usage} Downloaded: #{asset}", :green) unless options['quiet']
47
52
  end
48
53
  say("Done.", :green) unless options['quiet']
49
54
  end
@@ -157,6 +162,7 @@ module ShopifyTheme
157
162
  end
158
163
 
159
164
  def download_asset(key)
165
+ return unless valid?(key)
160
166
  notify_and_sleep("Approaching limit of API permits. Naptime until more permits become available!") if ShopifyTheme.needs_sleep?
161
167
  asset = ShopifyTheme.get_asset(key)
162
168
  if asset['value']
@@ -173,6 +179,7 @@ module ShopifyTheme
173
179
  end
174
180
 
175
181
  def send_asset(asset, quiet=false)
182
+ return unless valid?(asset)
176
183
  time = Time.now
177
184
  data = {:key => asset}
178
185
  content = File.read(asset)
@@ -183,19 +190,21 @@ module ShopifyTheme
183
190
  data.merge!(:value => content)
184
191
  end
185
192
 
186
- if (response = ShopifyTheme.send_asset(data)).success?
193
+ response = ShopifyTheme.send_asset(data)
194
+ if response.success?
187
195
  say("[" + time.strftime(TIMEFORMAT) + "] Uploaded: #{asset}", :green) unless quiet
188
196
  else
189
- say("[" + time.strftime(TIMEFORMAT) + "] Error: Could not upload #{asset}. #{errors_from_response(response)}", :red)
197
+ report_error(time, "Could not upload #{asset}", response)
190
198
  end
191
199
  end
192
200
 
193
201
  def delete_asset(key, quiet=false)
202
+ return unless valid?(key)
194
203
  time = Time.now
195
204
  if (response = ShopifyTheme.delete_asset(key)).success?
196
205
  say("[" + time.strftime(TIMEFORMAT) + "] Removed: #{key}", :green) unless quiet
197
206
  else
198
- say("[" + time.strftime(TIMEFORMAT) + "] Error: Could not remove #{key}. #{errors_from_response(response)}", :red)
207
+ report_error(time, "Could not remove #{key}", response)
199
208
  end
200
209
  end
201
210
 
@@ -204,19 +213,33 @@ module ShopifyTheme
204
213
  ShopifyTheme.sleep
205
214
  end
206
215
 
216
+ def valid?(key)
217
+ return true if DEFAULT_WHITELIST.include?(key.split('/').first + "/")
218
+ say("'#{key}' is not in a valid file for theme uploads", :yellow)
219
+ say("Files need to be in one of the following subdirectories: #{DEFAULT_WHITELIST.join(' ')}", :yellow)
220
+ false
221
+ end
222
+
223
+ def report_error(time, message, response)
224
+ say("[#{time.strftime(TIMEFORMAT)}] Error: #{message}", :red)
225
+ say("Error Details: #{errors_from_response(response)}", :yellow)
226
+ end
227
+
207
228
  def errors_from_response(response)
208
- return unless response.parsed_response
229
+ object = {status: response.headers['status'], request_id: response.headers['x-request-id']}
209
230
 
210
- errors = response.parsed_response["errors"]
231
+ errors = response.parsed_response ? response.parsed_response["errors"] : response.body
211
232
 
212
- case errors
233
+ object[:errors] = case errors
213
234
  when NilClass
214
235
  ''
215
236
  when String
216
- errors
237
+ errors.strip
217
238
  else
218
239
  errors.values.join(", ")
219
240
  end
241
+ object.delete(:errors) if object[:errors].length <= 0
242
+ object
220
243
  end
221
244
  end
222
245
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyTheme
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
5
- prerelease:
4
+ version: 0.0.16
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Duff
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.14.4
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.14.4
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: httparty
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,65 +55,57 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: filewatcher
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: launchy
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rake
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: minitest
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: 5.0.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: 5.0.0
126
111
  description: Command line tool to help with developing Shopify themes. Provides simple
@@ -141,6 +126,7 @@ files:
141
126
  - README.md
142
127
  - Rakefile
143
128
  - bin/theme
129
+ - doc/how_to_find_theme_id.png
144
130
  - lib/shopify_theme.rb
145
131
  - lib/shopify_theme/cli.rb
146
132
  - lib/shopify_theme/version.rb
@@ -150,33 +136,26 @@ files:
150
136
  homepage: https://github.com/Shopify/shopify_theme
151
137
  licenses:
152
138
  - MIT
139
+ metadata: {}
153
140
  post_install_message:
154
141
  rdoc_options: []
155
142
  require_paths:
156
143
  - lib
157
144
  required_ruby_version: !ruby/object:Gem::Requirement
158
- none: false
159
145
  requirements:
160
- - - ! '>='
146
+ - - '>='
161
147
  - !ruby/object:Gem::Version
162
148
  version: '0'
163
- segments:
164
- - 0
165
- hash: -577831141083631280
166
149
  required_rubygems_version: !ruby/object:Gem::Requirement
167
- none: false
168
150
  requirements:
169
- - - ! '>='
151
+ - - '>='
170
152
  - !ruby/object:Gem::Version
171
153
  version: '0'
172
- segments:
173
- - 0
174
- hash: -577831141083631280
175
154
  requirements: []
176
155
  rubyforge_project: shopify_theme
177
- rubygems_version: 1.8.23
156
+ rubygems_version: 2.0.3
178
157
  signing_key:
179
- specification_version: 3
158
+ specification_version: 4
180
159
  summary: Command line tool for developing themes
181
160
  test_files:
182
161
  - spec/spec_helper.rb