shopify_theme 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,26 +1,32 @@
1
+ # Edit your Shopify theme locally
2
+
3
+ The Shopify theme gem is a command line tool that lets you make live changes to your published theme.
4
+
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
+
1
7
  # Requirements
2
8
 
3
9
  Ruby 1.9
4
10
 
5
11
  # Installation
6
12
 
7
- ````
13
+ ```
8
14
  gem install shopify_theme [optional_theme_id]
9
- ````
15
+ ```
10
16
 
11
17
  # Usage
12
18
 
13
- 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.
19
+ 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`.
14
20
 
15
- ````
21
+ ```
16
22
  theme configure api_key password store_url
17
- ````
23
+ ```
18
24
 
19
25
  Example of config.yml. Notice store has no http or https declaration. You can
20
26
  use `:whitelist_files:` to specify files for upload. The `assets/`, `config/`,
21
27
  `layout/`, `snippets/` and `templates/` directories are included by default.
22
28
 
23
- ````
29
+ ```yaml
24
30
  ---
25
31
  :api_key: 7a8da86d3dd730b67a357dedabaac5d6
26
32
  :password: 552338ce0d3aba7fc501dcf99bc57a81
@@ -29,43 +35,43 @@ use `:whitelist_files:` to specify files for upload. The `assets/`, `config/`,
29
35
  :whitelist_files:
30
36
  - directoryToUpload/
31
37
  - importantFile.txt
32
- ````
38
+ ```
33
39
 
34
40
  Download all the theme files
35
41
 
36
- ````
42
+ ```
37
43
  theme download
38
- ````
44
+ ```
39
45
 
40
46
  Upload a theme file
41
47
 
42
- ````
48
+ ```
43
49
  theme upload assets/layout.liquid
44
- ````
50
+ ```
45
51
 
46
52
  Remove a theme file
47
53
 
48
- ````
54
+ ```
49
55
  theme remove assets/layout.liquid
50
- ````
56
+ ```
51
57
 
52
58
  Completely replace shop theme assets with the local assets
53
59
 
54
- ````
60
+ ```
55
61
  theme replace
56
- ````
62
+ ```
57
63
 
58
64
  Watch the theme directory and upload any files as they change
59
65
 
60
- ````
66
+ ```
61
67
  theme watch
62
- ````
68
+ ```
63
69
 
64
70
  Open the store in the default browser
65
71
 
66
- ````
72
+ ```
67
73
  theme open
68
- ````
74
+ ```
69
75
 
70
76
  # Common Problems
71
77
 
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
2
  module ShopifyTheme
3
3
  include HTTParty
4
+ @@current_api_call_count = 0
5
+ @@total_api_calls = 40
4
6
 
5
7
  NOOPParser = Proc.new {|data, format| {} }
6
8
  TIMER_RESET = 5 * 60 + 5
@@ -5,7 +5,7 @@ require 'abbrev'
5
5
  require 'base64'
6
6
  require 'fileutils'
7
7
  require 'json'
8
- require 'listen'
8
+ require 'filewatcher'
9
9
  require 'launchy'
10
10
 
11
11
  module ShopifyTheme
@@ -50,9 +50,7 @@ module ShopifyTheme
50
50
 
51
51
  desc "open", "open the store in your browser"
52
52
  def open(*keys)
53
- config = YAML.load_file 'config.yml'
54
- url = config[:store]
55
- if Launchy.open url
53
+ if Launchy.open shop_theme_url
56
54
  say("Done.", :green)
57
55
  end
58
56
  end
@@ -100,30 +98,51 @@ module ShopifyTheme
100
98
  method_option :keep_files, :type => :boolean, :default => false
101
99
  def watch
102
100
  puts "Watching current folder: #{Dir.pwd}"
103
- listener = Listen.to(Dir.pwd) do |modified, added, removed|
104
- modified.each do |filePath|
105
- filePath.slice!(Dir.pwd + "/")
106
- send_asset(filePath, options['quiet']) if local_assets_list.include?(filePath)
107
- end
108
- added.each do |filePath|
109
- filePath.slice!(Dir.pwd + "/")
110
- send_asset(filePath, options['quiet']) if local_assets_list.include?(filePath)
111
- end
112
- unless options['keep_files']
113
- removed.each do |filePath|
114
- filePath.slice!(Dir.pwd + "/")
115
- delete_asset(filePath, options['quiet']) if !local_assets_list.include?(filePath)
101
+ watcher do |filename, event|
102
+ filename = filename.gsub("#{Dir.pwd}/", '')
103
+ if local_assets_list.include?(filename)
104
+ action = case event
105
+ when :changed, :new then :send_asset
106
+ when :delete then :delete_asset
107
+ else raise NotImplementedError, "Unknown event -- #{event}"
116
108
  end
109
+ send(action, filename, options['quiet'])
117
110
  end
118
111
  end
119
- listener.start
120
- sleep
121
- rescue Interrupt
122
- puts "exiting...."
112
+ end
113
+
114
+ desc "systeminfo", "print out system information and actively loaded libraries for aiding in submitting bug reports"
115
+ def systeminfo
116
+ ruby_version = "#{RUBY_VERSION}"
117
+ ruby_version += "-p#{RUBY_PATCHLEVEL}" if RUBY_PATCHLEVEL
118
+ puts "Ruby: v#{ruby_version}"
119
+ puts "Operating System: #{RUBY_PLATFORM}"
120
+ %w(Thor Listen HTTParty Launchy).each do |lib|
121
+ require "#{lib.downcase}/version"
122
+ puts "#{lib}: v" + Kernel.const_get("#{lib}::VERSION")
123
+ end
124
+ end
125
+
126
+ protected
127
+
128
+ def config
129
+ @config ||= YAML.load_file 'config.yml'
130
+ end
131
+
132
+ def shop_theme_url
133
+ url = config[:store]
134
+ url += "?preview_theme_id=#{config[:theme_id]}" if config[:theme_id] && config[:theme_id].to_i > 0
135
+ url
123
136
  end
124
137
 
125
138
  private
126
139
 
140
+ def watcher
141
+ FileWatcher.new(Dir.pwd).watch() do |filename, event|
142
+ yield(filename, event)
143
+ end
144
+ end
145
+
127
146
  def local_assets_list
128
147
  local_files.reject do |p|
129
148
  @permitted_files ||= (DEFAULT_WHITELIST | ShopifyTheme.whitelist_files).map{|pattern| Regexp.new(pattern)}
@@ -1,3 +1,3 @@
1
1
  module ShopifyTheme
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency("thor", [">= 0.14.4"])
18
18
  s.add_dependency("httparty", "~> 0.10.0")
19
19
  s.add_dependency("json", "~> 1.5.4")
20
- s.add_dependency("listen", "~>2.0")
20
+ s.add_dependency("filewatcher")
21
21
  s.add_dependency("launchy")
22
22
 
23
23
  s.add_development_dependency 'rake'
@@ -6,7 +6,17 @@ module ShopifyTheme
6
6
  describe "Cli" do
7
7
 
8
8
  class CliDouble < Cli
9
- attr_writer :local_files
9
+ attr_writer :local_files, :mock_config
10
+
11
+ desc "",""
12
+ def config
13
+ @mock_config || super
14
+ end
15
+
16
+ desc "",""
17
+ def shop_theme_url
18
+ super
19
+ end
10
20
 
11
21
  desc "", ""
12
22
  def local_files
@@ -23,5 +33,18 @@ module ShopifyTheme
23
33
  assert_equal 2, @cli.send(:local_assets_list).length
24
34
  assert_equal false, @cli.send(:local_assets_list).include?('config.yml')
25
35
  end
36
+
37
+ it "should generate the shop path URL to the query parameter preview_theme_id if the id is present" do
38
+ @cli.mock_config = {store: 'somethingfancy.myshopify.com', theme_id: 12345}
39
+ assert_equal "somethingfancy.myshopify.com?preview_theme_id=12345", @cli.shop_theme_url
40
+ end
41
+
42
+ it "should generate the shop path URL withouth the preview_theme_id if the id is not present" do
43
+ @cli.mock_config = {store: 'somethingfancy.myshopify.com'}
44
+ assert_equal "somethingfancy.myshopify.com", @cli.shop_theme_url
45
+
46
+ @cli.mock_config = {store: 'somethingfancy.myshopify.com', theme_id: ''}
47
+ assert_equal "somethingfancy.myshopify.com", @cli.shop_theme_url
48
+ end
26
49
  end
27
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-26 00:00:00.000000000 Z
12
+ date: 2014-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -60,21 +60,21 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.5.4
62
62
  - !ruby/object:Gem::Dependency
63
- name: listen
63
+ name: filewatcher
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '2.0'
69
+ version: '0'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '2.0'
77
+ version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: launchy
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -344329295272915207
165
+ hash: -577831141083631280
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: -344329295272915207
174
+ hash: -577831141083631280
175
175
  requirements: []
176
176
  rubyforge_project: shopify_theme
177
177
  rubygems_version: 1.8.23