ruby-bitly 0.0.6 → 0.0.8

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 (6) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION +1 -1
  3. data/bin/bitly +9 -40
  4. data/lib/readme.rb +136 -0
  5. data/ruby-bitly.gemspec +2 -1
  6. metadata +4 -3
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = This app is a simple bitly ruby client.
1
+ = A simple bitly ruby client.
2
2
 
3
3
  == Examples
4
4
  bitly -s http://rafael.xlii.com.br
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.8
data/bin/bitly CHANGED
@@ -1,44 +1,11 @@
1
- #!/usr/bin/env ruby
2
- # = This app is a simple bitly ruby client.
3
- #
4
- # == Examples
5
- # bitly -s http://rafael.xlii.com.br
6
- # bitly -e http://bit.ly/XLII42
7
- # bitly --user-clicks http://bit.ly/XLII42
8
- # bitly --global-clicks http://bit.ly/XLII42
9
- #
10
- # Other examples:
11
- # bitly -q -s http://rafael.xlii.com.br
12
- # bitly --verbose -e http://bit.ly/XLII42
13
- #
14
- # == Usage
15
- # bitly [options] url
16
- #
17
- # For help: bitly -h
18
- #
19
- # == Options
20
- # -s, --shorten Shorten a long url
21
- # -e, --expand Expand a short bitly url
22
- # -u, --user-clicks Show user clicks from the short bitly url
23
- # -g, --global-clicks Show global clicks from the short bitly url
24
- #
25
- # -h, --help Displays help message, then exit
26
- # -v, --version Display the version, then exit
27
- # -q, --quiet Output as little as possible, overrides verbose
28
- # -V, --verbose Verbose output
29
- #
30
- # == Author
31
- # rafaeldx7 ~ rafaeldx7(a)gmail.com
32
- #
33
- # == Copyright
34
- # Copyright (c) 2010 rafaeldx7. Licensed under the MIT License:
35
- # http://www.opensource.org/licenses/mit-license.php
1
+ #!/usr/bin/env ruby
36
2
 
37
3
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
38
4
 
5
+ require 'rubygems'
39
6
  require 'ruby-bitly'
40
7
  require 'optparse'
41
- require 'rdoc/usage'
8
+ require 'readme'
42
9
  require 'ostruct'
43
10
  require 'date'
44
11
 
@@ -123,11 +90,11 @@ class App
123
90
  end
124
91
 
125
92
  def output_help
126
- RDoc::usage() #exits app
93
+ Readme::usage() #exits app
127
94
  end
128
95
 
129
96
  def output_usage
130
- RDoc::usage('usage') # gets usage from comments above
97
+ Readme::usage('usage') # gets usage from comments above
131
98
  end
132
99
 
133
100
  def output_version
@@ -142,5 +109,7 @@ class App
142
109
  end
143
110
  end
144
111
 
145
- app = App.new(ARGV, STDIN)
146
- app.run
112
+ if __FILE__ == $0
113
+ app = App.new(ARGV, STDIN)
114
+ app.run
115
+ end
data/lib/readme.rb ADDED
@@ -0,0 +1,136 @@
1
+ require 'rdoc/markup/simple_markup'
2
+ require 'rdoc/markup/simple_markup/to_flow'
3
+ require 'rdoc/ri/ri_formatter'
4
+ require 'rdoc/ri/ri_options'
5
+
6
+ module Readme
7
+
8
+ # Display usage information from the comment at the top of
9
+ # the file. String arguments identify specific sections of the
10
+ # comment to display. An optional integer first argument
11
+ # specifies the exit status (defaults to 0)
12
+
13
+ def Readme.usage(*args)
14
+ exit_code = 0
15
+
16
+ if args.size > 0
17
+ status = args[0]
18
+ if status.respond_to?(:to_int)
19
+ exit_code = status.to_int
20
+ args.shift
21
+ end
22
+ end
23
+
24
+ # display the usage and exit with the given code
25
+ usage_no_exit(*args)
26
+ exit(exit_code)
27
+ end
28
+
29
+ # Display usage
30
+ def Readme.usage_no_exit(*args)
31
+ # main_program_file = caller[-1].sub(/:\d+$/, '') # ruby-bitly
32
+ main_program_file = "README.rdoc"
33
+
34
+ comment = File.open(main_program_file) do |file|
35
+ find_comment(file)
36
+ end
37
+
38
+ comment = comment.gsub(/^\s*#/, '')
39
+
40
+ markup = SM::SimpleMarkup.new
41
+ flow_convertor = SM::ToFlow.new
42
+
43
+ flow = markup.convert(comment, flow_convertor)
44
+
45
+ format = "plain"
46
+
47
+ unless args.empty?
48
+ flow = extract_sections(flow, args)
49
+ end
50
+
51
+ options = RI::Options.instance
52
+ if args = ENV["RI"]
53
+ options.parse(args.split)
54
+ end
55
+ formatter = options.formatter.new(options, "")
56
+ formatter.display_flow(flow)
57
+ end
58
+
59
+ ######################################################################
60
+
61
+ private
62
+
63
+ # Find the first comment in the file (that isn't a shebang line)
64
+ # If the file doesn't start with a comment, report the fact
65
+ # and return empty string
66
+
67
+ def Readme.gets(file)
68
+ if (line = file.gets) && (line =~ /^#!/) # shebang
69
+ throw :exit, find_comment(file)
70
+ else
71
+ line
72
+ end
73
+ end
74
+
75
+ def Readme.find_comment(file)
76
+ catch(:exit) do
77
+ # skip leading blank lines
78
+ 0 while (line = gets(file)) && (line =~ /^\s*$/)
79
+
80
+ comment = []
81
+ while line # && line =~ /^\s*#/ # ruby-bitly
82
+ comment << line
83
+ line = gets(file)
84
+ end
85
+
86
+ 0 while line && (line = gets(file))
87
+ return no_comment if comment.empty?
88
+ return comment.join
89
+ end
90
+ end
91
+
92
+
93
+ #####
94
+ # Given an array of flow items and an array of section names, extract those
95
+ # sections from the flow which have headings corresponding to
96
+ # a section name in the list. Return them in the order
97
+ # of names in the +sections+ array.
98
+
99
+ def Readme.extract_sections(flow, sections)
100
+ result = []
101
+ sections.each do |name|
102
+ name = name.downcase
103
+ copy_upto_level = nil
104
+
105
+ flow.each do |item|
106
+ case item
107
+ when SM::Flow::H
108
+ if copy_upto_level && item.level >= copy_upto_level
109
+ copy_upto_level = nil
110
+ else
111
+ if item.text.downcase == name
112
+ result << item
113
+ copy_upto_level = item.level
114
+ end
115
+ end
116
+ else
117
+ if copy_upto_level
118
+ result << item
119
+ end
120
+ end
121
+ end
122
+ end
123
+ if result.empty?
124
+ puts "Note to developer: requested section(s) [#{sections.join(', ')}] not found"
125
+ result = flow
126
+ end
127
+ result
128
+ end
129
+
130
+ #####
131
+ # Report the fact that no doc comment count be found
132
+ def Readme.no_comment
133
+ $stderr.puts "No usage information available for this program"
134
+ ""
135
+ end
136
+ end
data/ruby-bitly.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-bitly}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rafaeldx7"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bin/bitly",
29
+ "lib/readme.rb",
29
30
  "lib/ruby-bitly.rb",
30
31
  "ruby-bitly.gemspec",
31
32
  "spec/ruby-bitly_spec.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-bitly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - rafaeldx7
@@ -99,6 +99,7 @@ files:
99
99
  - Rakefile
100
100
  - VERSION
101
101
  - bin/bitly
102
+ - lib/readme.rb
102
103
  - lib/ruby-bitly.rb
103
104
  - ruby-bitly.gemspec
104
105
  - spec/ruby-bitly_spec.rb