squarespace-sync 0.0.1 → 0.0.2

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: 838bce92e3947380a1d4d6dd6bce462d44045411
4
- data.tar.gz: cb6553212cf083cc00a2f429f3a0a3bf841226bc
3
+ metadata.gz: 249d5912232d3b6c400770ea2eadfd1025c5b504
4
+ data.tar.gz: a97829f5a14af20723c33f8ee52c6d6a7dc4cc5b
5
5
  SHA512:
6
- metadata.gz: 1a3a966314f615054ba75ddb49da18afb0cec9102de10896ce2f05bceb18659bd4c969417b186a448666ecf36c6e0c476621ea1e8c274a17105efd9cdb2f29e8
7
- data.tar.gz: 48f38a1f0e91108fb6244d55871294de834ed64fb6e1eaee3f72894a71c3fd4a42abf19ba358d8d4b0a0dc617f934d9f7c57c6963abc3fcd92b0f43c3383d375
6
+ metadata.gz: b1005d5a7542cc92cceea81f3fa1b11adedfdb59f1411190cd96306c1a698192ab5e80507998ec5887b4ada97a6258fdeac0c40bb63fa137d6a30564c5d0db3a
7
+ data.tar.gz: 45b87d2cb0ed9dceb2cc95b43b813a0f8aa5380eb6f5e98f27cd03c48e5f60290387f38dd118735d7637c21bbd56ace956f27b93c49fa5be217505d4a30b2d34
data/README.md CHANGED
@@ -26,16 +26,18 @@ $ squarespace setup
26
26
 
27
27
  Update `squarespace.yaml` with your account settings, and then you can run either of these commands:
28
28
 
29
- Pull files from Squarespace. Warns if there are conflicts
29
+ Pull all files or a single file from Squarespace. Warns if there are conflicts
30
30
 
31
31
  ```
32
32
  $ squarespace pull
33
+ $ squarespace pull template.conf
33
34
  ```
34
35
 
35
- Push files to Squarespace, overwriting existing
36
+ Push all files or a single file to Squarespace, overwriting existing
36
37
 
37
38
  ```
38
39
  $ squarespace push
40
+ $ squarespace push template.conf
39
41
  ```
40
42
 
41
43
 
@@ -23,17 +23,27 @@ module Squarespace
23
23
  template( template_file, output_file, options )
24
24
  end
25
25
 
26
- desc "push", "Push files to Squarespace"
27
- def push
28
- Connection.new do |sftp, options, connection|
29
- connection.push_tree( sftp, options[:directory] )
26
+ desc "push FILE", "Push files to Squarespace"
27
+ def push(file=nil)
28
+ Connection.new do |sftp, options, instance|
29
+ if file
30
+ local_file = File.join(Squarespace::Sync.local_path, file)
31
+ instance.push_file( sftp, file, File.join(options[:directory], local_file) )
32
+ else
33
+ instance.push_tree( sftp, options[:directory] )
34
+ end
30
35
  end
31
36
  end
32
37
 
33
- desc "pull", "Pull files from Squarespace"
34
- def pull
35
- Connection.new do |sftp, options, connection|
36
- connection.pull_tree( sftp, options[:directory] )
38
+ desc "pull FILE", "Pull files from Squarespace"
39
+ def pull(file=nil)
40
+ Connection.new do |sftp, options, instance|
41
+ if file
42
+ local_file = File.join(Squarespace::Sync.local_path, file)
43
+ instance.pull_file( sftp, File.join(options[:directory], file), local_file )
44
+ else
45
+ instance.pull_tree( sftp, options[:directory] )
46
+ end
37
47
  end
38
48
  end
39
49
 
@@ -16,47 +16,56 @@ module Squarespace
16
16
 
17
17
  def pull_tree( sftp, directory )
18
18
  sftp.dir[directory, "**/*"].each do |entry|
19
- remote_file = File.join(directory, entry.name)
20
- local_file = File.join(Squarespace::Sync.local_path, entry.name)
19
+ remote = File.join(directory, entry.name)
20
+ local = File.join(Squarespace::Sync.local_path, entry.name)
21
21
 
22
- if sftp.file.directory?( remote_file )
23
- FileUtils.mkdir_p( local_file )
22
+ if sftp.file.directory?( remote )
23
+ FileUtils.mkdir_p( local )
24
24
  else
25
- if File.exists?( local_file )
26
- overwrite = ask("#{entry.name} already exists. Overwrite it?", :yellow, limited_to: %w{y n})
27
- if overwrite == "y"
28
- sftp.download!(remote_file, local_file)
29
- end
30
- else
31
- say("Downloading #{entry.name}", :green)
32
- sftp.download!(remote_file, local_file)
33
- end
25
+ pull_file( sftp, remote, local )
34
26
  end
35
27
  end
36
28
  end
37
29
 
30
+ def pull_file( sftp, remote, local )
31
+ if File.exists?( local )
32
+ overwrite = ask("#{local} already exists. Overwrite it?", :yellow, limited_to: %w{y n})
33
+ if overwrite == "y"
34
+ say("Downloading #{remote}", :green)
35
+ sftp.download!(remote, local)
36
+ end
37
+ else
38
+ say("Downloading #{remote}", :green)
39
+ sftp.download!(remote, local)
40
+ end
41
+ end
42
+
38
43
  def push_tree( sftp, directory )
39
- Dir[File.join(Squarespace::Sync.local_path, "**/*")].each do |file|
40
- remote_file = file.gsub(Squarespace::Sync.local_path + "/", "")
41
- real_path = File.join(directory, remote_file)
42
- next if Squarespace::Sync.options[:ignore].include?( remote_file.split("/").first )
44
+ Dir[File.join(Squarespace::Sync.local_path, "**/*")].each do |local|
45
+ remote = local.gsub(Squarespace::Sync.local_path + "/", "")
46
+ absolute_remote = File.join(directory, remote)
47
+ next if Squarespace::Sync.options[:ignore].include?( remote.split("/").first )
43
48
 
44
- if File.directory?( file )
45
- sftp.mkdir!( real_path ) unless sftp.file.directory?( real_path )
49
+ if File.directory?( local )
50
+ sftp.mkdir!( absolute_remote ) unless sftp.file.directory?( absolute_remote )
46
51
  else
47
- say("Uploading #{remote_file}", :green)
48
-
49
- begin
50
- sftp.upload!( file, real_path )
51
- rescue Net::SFTP::StatusException => code
52
- sftp.remove!( real_path ) do
53
- sftp.upload!( file, real_path )
54
- end if code == 11
55
- end
52
+ push_file( sftp, local, absolute_remote)
56
53
  end
57
54
  end
58
55
  end
59
56
 
57
+ def push_file( sftp, local, remote )
58
+ say("Uploading #{remote}", :green)
59
+
60
+ begin
61
+ sftp.upload!( local, remote )
62
+ rescue Net::SFTP::StatusException => code
63
+ sftp.remove!( remote ) do
64
+ sftp.upload!( local, remote )
65
+ end if code == 11
66
+ end
67
+ end
68
+
60
69
  end
61
70
 
62
71
  end
@@ -1,5 +1,5 @@
1
1
  module Squarespace
2
2
  module Sync
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squarespace-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jordanandree