restoready_theme 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fa63eb9380ffed3c2867649c674011429b4516e
4
- data.tar.gz: b420d42b574198345b56618fe9937a0bd103d529
3
+ metadata.gz: 443b90f02c5f4ea4932d5917504db08d97fce364
4
+ data.tar.gz: 0793d04dbb63e7829fceabb42563db21c0319f31
5
5
  SHA512:
6
- metadata.gz: 1bde77bf2cea4eb8e7b3791cbe35e948530f62f5dc0370a5349f41bf304beef44be77518b59c051e8054aa98f51a0db1879bdac90f5e1a2483c4f39769c6da5b
7
- data.tar.gz: 12b1e76a208cf1226685c2f6bdf977e34f7b5698e5484a9cd7155b553d5742217148d0c4c12b475a5ec763b3c566a8680259839e4b69a7a83c23f2470e90992b
6
+ metadata.gz: 43dad7653085c3b4df936751d4035b54c898db4a44b4fd8236cbda93eeb1b4d54de29c37249ba591f043bc4c5ff8ffae2b35805e4f117be4d5fd51b2790944a6
7
+ data.tar.gz: 084e221446b587dc29b4fc9e067b275f929951feb934a30e4b388bba45a79388a2274ab193ff35830f30006aaabb7d5d7d49681e950498623eaa1fcdf178fe8d
data/CHANGELOG.md CHANGED
@@ -0,0 +1,12 @@
1
+ # v1.0.0
2
+
3
+ * stable version
4
+
5
+ # v0.0.3
6
+
7
+ * Add bootstrap command (with Starter)
8
+ * Do not exit the gem after an error report
9
+
10
+ # v0.0.2
11
+
12
+ * Add download command
data/README.md CHANGED
@@ -21,7 +21,7 @@ To install the restoready_theme gem use 'gem install'.
21
21
  gem install restoready_theme
22
22
  ```
23
23
 
24
- or add this line in Gemfile
24
+ or add this line in Gemfile and run `bundle install`
25
25
 
26
26
  ```
27
27
  gem restoready_theme
@@ -41,6 +41,12 @@ Generate the config file. To choose the theme you want to edit, add `theme_id`.
41
41
  theme configure api_key api_url site_url theme_id
42
42
  ```
43
43
 
44
+ Or bootstrap a new theme with [Starter](https://github.com/restoready/starter)
45
+
46
+ ```
47
+ theme bootstrap api_key api_url site_url theme_name
48
+ ```
49
+
44
50
  Example of config.yml. You can use `:whitelist_files:` to specify files for upload. The `assets/`, `config/`,
45
51
  `layouts/`, `snippets/`, `templates/` and `locales/`directories are included by
46
52
  default.
@@ -73,6 +79,12 @@ Remove a theme file
73
79
  theme remove assets/layout.liquid
74
80
  ```
75
81
 
82
+ to download the thème given in config
83
+
84
+ ```
85
+ theme download
86
+ ```
87
+
76
88
  Completely replace theme assets with the local assets
77
89
 
78
90
  ```
@@ -42,6 +42,30 @@ module RestoreadyTheme
42
42
  check
43
43
  end
44
44
 
45
+ desc "bootstrap API_KEY API_URL SITE_URL THEME_NAME", "bootstrap with Starter to site and configure local directory."
46
+ def bootstrap(api_key=nil, api_url=nil, site_url = nil, theme_name = 'starter')
47
+ config = {:api_key => api_key, :api_url => api_url, :site_url => site_url}
48
+
49
+ say("Creating directory named #{theme_name}", :green)
50
+ if File.directory?(theme_name)
51
+ say("Directory #{theme_name} existing, choose another theme name", :red)
52
+ exit
53
+ else
54
+ empty_directory(theme_name)
55
+ end
56
+
57
+ say("Registering #{theme_name} theme on #{site_url}", :green)
58
+ theme_info = RestoreadyTheme::HttpClient.new(api_url, api_key).install_starter(theme_name)
59
+
60
+ say("Saving configuration to #{theme_name}", :green)
61
+ config.merge!(theme_id: theme_info['id'])
62
+ create_file("#{theme_name}/config.yml", config.to_yaml)
63
+
64
+ say("Downloading #{theme_name} assets from RestoReady")
65
+ Dir.chdir(theme_name)
66
+ download()
67
+ end
68
+
45
69
  desc "open", "open the site in your browser"
46
70
  def open(*keys)
47
71
  if Launchy.open restoready_theme_url
@@ -112,7 +136,7 @@ module RestoreadyTheme
112
136
  method_option :keep_files, type: :boolean, default: false
113
137
  def watch
114
138
  check
115
- puts "Surveille le répertoire courant: #{Dir.pwd}"
139
+ puts "Watching current folder: #{Dir.pwd}"
116
140
  watcher do |filename, event|
117
141
  filename = filename.gsub("#{Dir.pwd}/", '')
118
142
 
@@ -274,7 +298,6 @@ module RestoreadyTheme
274
298
  def report_error(time, message, response)
275
299
  say("[#{timestamp(time)}] Error: #{message}", :red)
276
300
  say("Error Details: #{errors_from_response(response)}", :yellow)
277
- exit
278
301
  end
279
302
 
280
303
  def errors_from_response(response)
@@ -3,9 +3,16 @@ module RestoreadyTheme
3
3
  class HttpClient
4
4
  attr_accessor :client
5
5
 
6
- def initialize(api_url = nil)
7
- # api_url = base_url.nil? ? config[:api_url] : base_url
8
- @client = ::Faraday.new(url: api_url ||= config[:api_url])
6
+ STARTER_ZIP = "https://codeload.github.com/restoready/starter/zip/master"
7
+
8
+ def initialize(api_url = nil, api_key = nil)
9
+ @api_key = api_key || config[:api_key]
10
+ @client = Faraday.new(url: api_url ||= config[:api_url]) do |conn|
11
+ conn.request :multipart
12
+ conn.request :url_encoded
13
+
14
+ conn.adapter :net_http
15
+ end
9
16
  end
10
17
 
11
18
  def test?
@@ -68,6 +75,31 @@ module RestoreadyTheme
68
75
  response
69
76
  end
70
77
 
78
+ def get_starter
79
+ source = STARTER_ZIP
80
+ response = client.get do |req|
81
+ req.url "#{source}"
82
+ req.headers['Authorization'] = token
83
+ req.headers['Accept'] = 'application/zip'
84
+ req.headers['Accept-Encoding'] = 'gzip'
85
+ end
86
+ response.status == 200 ? response.body : nil
87
+ end
88
+
89
+ def install_starter(theme_name)
90
+ Dir.mktmpdir do |dir|
91
+ File.open("#{dir}/starter-master.zip", 'wb') { |fp| fp.write(get_starter) }
92
+ response = client.post do |req|
93
+ req.url "/api/v1/themes"
94
+ req.headers['Authorization'] = token
95
+ req.body = {theme: {file: Faraday::UploadIO.new("#{dir}/starter-master.zip", 'application/zip'), name: theme_name}}
96
+ end
97
+ theme = response.status == 200 ? JSON.parse(response.body) : {}
98
+ theme.merge!(response: response)
99
+ theme
100
+ end
101
+ end
102
+
71
103
  def config
72
104
  @config ||= if File.exist? 'config.yml'
73
105
  config = YAML.load(File.read('config.yml'))
@@ -117,8 +149,8 @@ module RestoreadyTheme
117
149
 
118
150
  private
119
151
 
120
- def token
121
- "Token token=\"#{config[:api_key]}\""
122
- end
152
+ def token
153
+ "Token token=\"#{@api_key}\""
154
+ end
123
155
  end
124
156
  end
@@ -1,3 +1,3 @@
1
1
  module RestoreadyTheme
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -55,7 +55,7 @@ describe RestoreadyTheme::Cli do
55
55
 
56
56
  it "should generate the restoready path URL to the query parameter preview_theme_id if the id is present" do
57
57
  @cli.mock_config = {site_url: 'somethingfancy.com', theme_id: 12345}
58
- expect(@cli.restoready_theme_url).to eq "somethingfancy.com?preview_theme_id=12345"
58
+ expect(@cli.restoready_theme_url).to eq "somethingfancy.com/fr?preview_theme_id=12345"
59
59
  end
60
60
 
61
61
  it "should generate the restoready path URL withouth the preview_theme_id if the id is not present" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restoready_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derivery Damien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor