gistribute 0.0.1 → 0.1

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.
Files changed (5) hide show
  1. data/README.md +20 -32
  2. data/VERSION +1 -1
  3. data/bin/gistribute +24 -27
  4. data/gistribute.gemspec +1 -2
  5. metadata +4 -20
data/README.md CHANGED
@@ -15,42 +15,30 @@ a tweak to one of the files that you're sharing.
15
15
 
16
16
  ## How It Works
17
17
 
18
- Gistribute looks at the files in each Gist and checks for one or two lines of
19
- metadata at the top of the file. The metadata must begin with ```%%```, but
20
- you may put anything before that and it won't be parsed.
21
-
22
- The first line of metadata contains the location on the client's computer that
23
- you wish to install the file to. The second contains the name of the file as it
24
- will be printed on the user's screen as it is installed. If the second line is
25
- excluded, Gistribute will use the name of the file in the Gist.
18
+ Gistribute looks at the filename that you enter on Gist to find all of the
19
+ data that it needs to download the file to the other user's computer. It
20
+ allows you to choose what Gistribute will call the file when it is installing
21
+ it, and where it will install the file.
26
22
 
27
23
  ## Usage
28
24
 
29
- An example follows:
30
-
31
- ```VimL
32
- "%% ~/.vimrc
33
- "%% Vim configuration
34
- " This is an example .vimrc file being shared via Gistribute.
35
- " Notice the two comments at the top containing the metadata.
25
+ If, for example, you were sharing a .vimrc file, and you wanted Gistribute to
26
+ call it "Vim configuration" when it was installing it, you would name the file
27
+ `Vim configuration||~|.vimrc`. If the filename contains the sequence `||`,
28
+ anything before that will be considered the description of that file, and
29
+ anything after it the installation path. If there is no `||`, Gistribute will
30
+ use the name of the file (without the path to it) as the default description.
36
31
 
37
- set nocompatible
38
- filetype indent plugin on
39
- syntax on
40
- ```
32
+ The file path separator is the pipe character because GitHub Gist doesn't
33
+ allow slashes in filenames- this quirk is the result of Gist actually saving
34
+ those files to a Git repository on their servers, and handling slashes in
35
+ file names can't possibly be very nice.
41
36
 
42
- If, for example, the resulting Gist link was https://gist.github.com/123456,
37
+ If the resulting Gist link was, for example, https://gist.github.com/123456,
43
38
  the user would be able to run either of these commands to download the file
44
- to ```~/.vimrc```:
39
+ to `~/.vimrc`:
45
40
 
46
- $ gistribute 123456
47
- $ gistribute https://gist.github.com/123456
48
-
49
- **Gistribute will strip the metadata from the files.** Don't worry about having
50
- messy files on the user's computer because of the metadata sitting at the top,
51
- as this is taken care of. Be aware, however, that if you leave a blank line
52
- between the metadata and the first line of the file, the resulting downloaded
53
- file **will** have a blank line at the top.
54
-
55
- If there are files in the Gist without metadata, they will be ignored by
56
- Gistribute.
41
+ ```Shell
42
+ $ gistribute 123456
43
+ $ gistribute https://gist.github.com/123456
44
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1
data/bin/gistribute CHANGED
@@ -6,13 +6,13 @@ if %w[-v --version].include? ARGV.first
6
6
  end
7
7
 
8
8
  require "json"
9
+ require "fileutils"
9
10
  require "open-uri"
10
- require "colorize"
11
11
  require "nutella"
12
12
 
13
13
  print "Downloading data..."
14
14
 
15
- # The user can paste in either just the ID or the entire URL to the Gist.
15
+ # The user can pass in either just the ID or the entire URL to the Gist.
16
16
  id = ARGV.first[/(^|\/)([[:xdigit:]]+)/, 2]
17
17
 
18
18
  begin
@@ -52,38 +52,35 @@ end
52
52
  # }
53
53
  # }
54
54
 
55
- puts <<-EOS.heredoc
56
-
57
-
58
- Finished downloading Gist from: #{gist["html_url"]}
59
- Gist uploaded by #{
60
- gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
61
- }.
62
-
63
- Beginning install...
55
+ # Regular expression word wrap to keep lines less than 80 characters. Then
56
+ # check to see if it's empty- if not, put newlines on each side so that it
57
+ # will be padded when displayed in the output.
58
+ desc = gist["description"].gsub(/(.{1,79})(\s+|\Z)/, "\\1\n").strip
59
+ desc = "\n#{desc}\n" unless desc.empty?
60
+
61
+ puts <<EOS
62
+ \n
63
+ Finished downloading Gist from: #{gist["html_url"]}
64
+ Gist uploaded by #{
65
+ gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
66
+ }.
67
+ #{desc}
68
+ Beginning install...
64
69
  EOS
65
70
 
66
71
  gist["files"].each do |filename, data|
67
- lines = data["content"].lines.to_a
68
-
69
- # Parse out all metadata after %% on the first two lines, strip out
70
- # (lead|trail)ing whitespace while we're at it.
71
- metadata = lines[0..1].map { |line| line[/%%\s*(.*\S)\s*/, 1] }
72
-
73
- # Skip non-Gistribute files.
74
- next if metadata.first.nil?
72
+ metadata = filename.split("||").map &:strip
75
73
 
76
- puts " #{"*".green} Installing #{metadata[1] || filename}..."
74
+ # | as path separator in the Gist's file name, as Gist doesn't allow the
75
+ # usage of /.
76
+ path = metadata.last.gsub /[~|]/, "|" => "/", "~" => Dir.home
77
+ # Default description is the name of the file.
78
+ description = metadata.size == 1 ? File.basename(path) : metadata.first
77
79
 
78
- # TODO: Is there a better way to handle ~?
79
- path = metadata.first.gsub "~", Dir.home
80
+ puts " #{"*".green} Installing #{description}..."
80
81
 
81
82
  # Handle directories that don't exist.
82
83
  FileUtils.mkdir_p File.dirname(path)
83
84
 
84
- File.open(path, "w") do |f|
85
- # Remove all lines with metadata- lines that don't match will return nil,
86
- # so compact it and drop that many off the top of the file.
87
- f << lines[metadata.compact.size..-1].join
88
- end
85
+ File.write path, data["content"]
89
86
  end
data/gistribute.gemspec CHANGED
@@ -19,6 +19,5 @@ Gem::Specification.new do |gem|
19
19
  ]
20
20
 
21
21
  gem.add_dependency "json", "~> 1.7"
22
- gem.add_dependency "nutella", "~> 0.10"
23
- gem.add_dependency "colorize", "~> 0.5"
22
+ gem.add_dependency "nutella", "~> 0.11"
24
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '0.1'
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: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0.10'
37
+ version: '0.11'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,23 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0.10'
46
- - !ruby/object:Gem::Dependency
47
- name: colorize
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '0.5'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '0.5'
45
+ version: '0.11'
62
46
  description: Distribute files simply using GitHub Gist.
63
47
  email: vinny.diehl@gmail.com
64
48
  executables: