guard-shopify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3@guard-shopify
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-shopify.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ guard-shopify (0.0.1)
5
+ shopify_api (~> 2.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.1.3)
11
+ activesupport (= 3.1.3)
12
+ builder (~> 3.0.0)
13
+ i18n (~> 0.6)
14
+ activeresource (3.1.3)
15
+ activemodel (= 3.1.3)
16
+ activesupport (= 3.1.3)
17
+ activesupport (3.1.3)
18
+ multi_json (~> 1.0)
19
+ builder (3.0.0)
20
+ i18n (0.6.0)
21
+ multi_json (1.0.4)
22
+ shopify_api (2.2.0)
23
+ activeresource (>= 3.0.0)
24
+ thor (>= 0.14.4)
25
+ thor (0.14.6)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ guard-shopify!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jonan Scheffler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Guard::Shopify
2
+ ==============
3
+
4
+ The Shopify guard uploads template modifications directly to Shopify, allowing you to forego the existing Textmate bundle and use any editor you like to modify Shopify templates.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Please be sure to have [Guard](https://github.com/guard/guard) installed before you continue.
10
+
11
+ Install the gem:
12
+ $ gem install guard-shopify
13
+
14
+ Add it to your Gemfile (inside development group):
15
+
16
+ ``` ruby
17
+ group :development do
18
+ gem 'guard-shopify'
19
+ end
20
+ ```
21
+
22
+ Add the guard definition to your Guardfile:
23
+ $ guard init rspec
24
+
25
+ When first run the gem will prompt you to enter your API key, password and store url. Follow [these instructions](http://http://wiki.shopify.com/Shopify_Textmate_Bundle) to get this information (you only need to do it once).
26
+
27
+ Hello Hungry Academy
28
+ ====================
29
+
30
+ I wrote this project for two reasons: I needed a code sample for my hungry academy application and I wanted to make my own client work significantly less painful.
31
+
32
+ The best solution that existed before this gem was a Textmate bundle that allows you to upload modifications to Shopify with a keystroke. It sounds like a pretty good solution but Textmate and I broke up a long time ago and even having to save, upload, tab and refresh was a bit laborious for me.
33
+
34
+ It occurred to me that a guard could watch my filesystem for changes and upload modifications immediately on saving, allowing me to use vim instead of Textmate.
35
+
36
+ This gem is not as full featured as I would like it to be, nor is it well tested, but it is my first independent open source contribution that may actually get used, and I'm quite pleased with this first release.
37
+
38
+ The immediate roadmap for guard-shopify includes test coverage, the ability to upload new files, delete existing files and optionally prompt before uploading changes to Shopify.
39
+
40
+ I'm only counting the hungry academy section of this file towards the 200 word limit you specified; if that's unacceptable please let me know and I will remove the installation instructions.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/shopify/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-shopify"
7
+ s.version = Guard::Shopify::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jonan Scheffler"]
10
+ s.email = ["jonanscheffler+gem@gmail.com"]
11
+ s.homepage = "http://www.1337807.com"
12
+ s.summary = "Gem to upload Shopify template modifications."
13
+ s.description = %q{This gem allows guard to watch a Shopify template directory for changes and then upload them immediately to Shopify using their API.}
14
+
15
+ s.rubyforge_project = "guard-shopify"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'guard', '>= 0.10.0'
23
+ s.add_dependency 'shopify_api', '~> 2.2.0'
24
+ s.add_dependency 'ptools', '~> 1.2.1'
25
+ end
@@ -0,0 +1,86 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'shopify_api'
4
+ require 'ptools'
5
+
6
+ module Guard
7
+ class Shopify < Guard
8
+ def start
9
+ set_config unless File.exists?("#{ENV['HOME']}/.guard_shopify")
10
+ get_credentials_from_config
11
+ authenticate_with_shopify
12
+ get_main_theme_id
13
+ end
14
+
15
+ def get_credentials_from_config
16
+ credentials = File.read("#{ENV['HOME']}/.guard_shopify").split("\n")
17
+
18
+ @api_key = credentials[0]
19
+ @password = credentials[1]
20
+ @url = credentials[2]
21
+ end
22
+
23
+ def authenticate_with_shopify
24
+ ShopifyAPI::Base.site = "https://#{@api_key}:#{@password}@#{@url}/admin"
25
+ end
26
+
27
+ def get_main_theme_id
28
+ themes = ShopifyAPI::Theme.find(:all)
29
+
30
+ main_theme = themes.select {|t| t.role == 'main'}.first
31
+
32
+ @theme_id = main_theme.id
33
+ end
34
+
35
+ def run_on_change(paths)
36
+ paths.each do |p|
37
+ Notifier.notify("#{p} was changed.")
38
+ puts "#{p} was changed."
39
+
40
+ begin
41
+ remote_asset = ShopifyAPI::Asset.find(p, :params => {:theme_id => @theme_id})
42
+ rescue Exception => e
43
+ puts "Error retrieving remote asset matching #{p}; nothing uploaded."
44
+ puts e.message
45
+ end
46
+
47
+ if File.binary?(p) && remote_asset
48
+ upload_binary_asset(p, remote_asset)
49
+ elsif remote_asset
50
+ upload_text_asset(p, remote_asset)
51
+ end
52
+ end
53
+ end
54
+
55
+ def upload_binary_asset(path, remote_asset)
56
+ remote_asset.attach(File.read(path))
57
+ remote_asset.save
58
+ puts "#{path} uploaded to #{@url}"
59
+ end
60
+
61
+ def upload_text_asset(path, remote_asset)
62
+ local_text = File.read(path)
63
+ remote_asset.value = local_text
64
+ remote_asset.save
65
+ puts "#{path} uploaded to #{@url}"
66
+ end
67
+
68
+ private
69
+
70
+ def set_config
71
+ puts "This guard needs your API credentials to access your Shopify store."
72
+ puts "Please enter your API key:"
73
+ api_key = gets.chomp
74
+ puts "Please enter your password:"
75
+ password = gets.chomp
76
+ puts "Please enter your store's url (e.g. awesomesauce.myshopify.com):"
77
+ url = gets.chomp
78
+ url = url + '.myshopify.com' unless url.include?('myshopify.com')
79
+
80
+ config = [api_key, password, url].join("\n")
81
+
82
+ File.open("#{ENV['HOME']}/.guard_shopify", 'w') {|f| f.write(config) }
83
+ puts "Credentials saved to #{ENV['HOME']}/.guard_shopify"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ guard :shopify do
2
+ watch(/.*/)
3
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module Shopify
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-shopify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonan Scheffler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &70260468489040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70260468489040
25
+ - !ruby/object:Gem::Dependency
26
+ name: shopify_api
27
+ requirement: &70260468488480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70260468488480
36
+ - !ruby/object:Gem::Dependency
37
+ name: ptools
38
+ requirement: &70260468487780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70260468487780
47
+ description: This gem allows guard to watch a Shopify template directory for changes
48
+ and then upload them immediately to Shopify using their API.
49
+ email:
50
+ - jonanscheffler+gem@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .rvmrc
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - guard-shopify.gemspec
62
+ - lib/guard/shopify.rb
63
+ - lib/guard/shopify/templates/Guardfile
64
+ - lib/guard/shopify/version.rb
65
+ homepage: http://www.1337807.com
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: guard-shopify
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Gem to upload Shopify template modifications.
89
+ test_files: []