super_stamper 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/super_stamper.rb CHANGED
@@ -1,66 +1,149 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ###############################################################################
4
+ # super_stamper, a nifty tool that puts headers in all your source files.
5
+ # It does exactly what you see here: a header.txt file is pasted into every .rb file.
6
+ # Also, some random quotes can be added just for kicks.
7
+ #
8
+ # Protip: also install the magic_encoding gem alongside to use it like this:
9
+ # $ super_stamper -q && magic_encoding
10
+ #
11
+ # (c) 2012 Commander Johnson
12
+ # Licensed under the MIT license
13
+ ###############################################################################
2
14
 
3
- $:.unshift(File.dirname(__FILE__)) unless
4
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
15
+ #<wolf> 1. Save every Free Credit Card Offer you get, Put it in pile A
16
+ #<wolf> 2. Save every Free Coupon You get, put that in pile B
17
+ #<wolf> 3. Now open the credit card mail from pile A and find the Business
18
+ #&nbsp; &nbsp; &nbsp;&nbsp; Reply Mail Envelope.
19
+ #<wolf> 4. Take the coupons from pile B and stuff them in the envelope you hold
20
+ #&nbsp; &nbsp; &nbsp;&nbsp; in your hand.
21
+ #<wolf> 5. Drop the stuffed to the brim envelopes in your mail and walk away
22
+ #&nbsp; &nbsp; &nbsp;&nbsp; whistling.
23
+ #<wolf> I have now received two phone calls from the credit card companies
24
+ #&nbsp; &nbsp; &nbsp;&nbsp; telling me that they received a stuffed envelope with coupons rather
25
+ #&nbsp; &nbsp; &nbsp;&nbsp; then my application. They informed me that it they are not pleased that
26
+ #&nbsp; &nbsp; &nbsp;&nbsp; they footed the bill for the crap I sent them. I reply with "It says
27
+ #&nbsp; &nbsp; &nbsp;&nbsp; Business Reply Mail" I'm suggesting coupons to you to ensure that your
28
+ #&nbsp; &nbsp; &nbsp;&nbsp; business is more successful. They promptly hang up on me.
29
+ #<wolf> Now, I did this for about a month before it got boring, so I got an
30
+ #&nbsp; &nbsp; &nbsp;&nbsp; added idea! I added exactly 33 cents worth of pennies to the envelope
31
+ #&nbsp; &nbsp; &nbsp;&nbsp; so they paid EXTRA due to the weight. I got a call informing me about
32
+ #&nbsp; &nbsp; &nbsp;&nbsp; the money, I said it was a mistake and I demanded my change back. After
33
+ #&nbsp; &nbsp; &nbsp;&nbsp; yelling at the clerk and then to the supervisor they agreed to my
34
+ #&nbsp; &nbsp; &nbsp;&nbsp; demands and cut me a check for the money. I hold in my hand at this
35
+ #&nbsp; &nbsp; &nbsp;&nbsp; very moment a check from GTE Visa for exactly 33 cents.
36
+ # -- end header --
37
+
38
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
39
+
40
+ # try to include stuff for getting those quotes
41
+ begin
42
+ require 'simple-rss'
43
+ require 'nokogiri'
44
+ require 'open-uri'
45
+ rescue
46
+ end
5
47
 
6
48
  module SuperStamper
7
49
  # a version constant
8
- VERSION = '0.0.4'
50
+ VERSION = '0.0.5'
9
51
  # a class
10
52
  class Base
11
53
  BEGIN_HEADER = "# -- begin header --"
12
54
  END_HEADER = "# -- end header --"
13
55
  DEFAULT_HEADER_FILE_NAME = "header.txt"
14
56
  NEWLINE = "\n"
15
-
57
+ QUOTEFEED="http://feeds.sydv.net/top200-bash-quotes"
58
+
16
59
  def self.stamp_recursively(options = {})
60
+ #puts options.inspect
17
61
  extension = options[:extension] || "rb"
18
-
62
+
19
63
  count = 0
20
-
64
+
65
+ ##########################################################
66
+ # Optional: add quote from IRC.
67
+ # First make an inventory of all the quotes.
68
+ ##########################################################
69
+ quote_database = nil
70
+ # Add quote from IRC
71
+ if defined?(SimpleRSS) && defined?(Nokogiri) && options[:quote]
72
+ puts "super_stamper: You ordered some quotes. Let me see if I can arrange that for you ..."
73
+ # +_+ #
74
+ quotefeed = options[:quotefeed] || QUOTEFEED
75
+ # +_+ #
76
+ begin
77
+ puts "super_stamper: Getting quotes from #{quotefeed} ..."
78
+ # +_+ #
79
+ rss = SimpleRSS.parse open(quotefeed)
80
+ # get all descriptions.
81
+ # needs double escaping.
82
+ quote_database = rss.entries.collect { |e| "##{CGI.unescapeHTML(CGI.unescapeHTML(e[:description])).gsub(/\<br\s?\/\>/, "\n#").gsub("&nbsp;", "")}" }
83
+ puts "super_stamper: Successfully gathed quote database. Putting them into your source files like a smooth operator ..."
84
+ rescue => e
85
+ puts "super_stamper: Sorry, couldn't add quotes to your files."
86
+ puts "super_stamper: Error was: #{e}"
87
+ puts "super_stamper: Proceeding with normal operation."
88
+ end
89
+ end
90
+ ##########################################################
91
+
21
92
  Dir["**/*.#{extension}"].each do |f|
22
- le_stamp_options = { :filename => f, :header_file_name => options[:header_file_name] }
93
+ ########################################################
94
+ le_stamp_options = {:filename => f, :header_file_name => options[:header_file_name]}
95
+ ########################################################
96
+ # Quote?
97
+ ########################################################
98
+ le_stamp_options[:quote] = quote_database.sample unless quote_database.nil?
99
+ ########################################################
23
100
  stamp_single le_stamp_options
101
+ ########################################################
24
102
  count += 1
103
+ ########################################################
25
104
  end
26
-
105
+
27
106
  # Informative!
28
107
  puts "super_stamper: I inserted a header into #{count} files with extension .#{extension} (recursively)."
29
-
108
+
30
109
  count
31
110
  end
32
111
 
33
112
  def self.stamp_single(options = {})
34
113
  ret = nil
35
-
114
+
36
115
  file = nil
37
116
  header = nil
38
-
117
+
39
118
  filename = options[:filename]
40
119
  header_file_name = options[:header_file_name] || "header.txt"
41
-
120
+
42
121
  raise "I need a filename" if filename.nil?
43
122
  raise "Please provide a valid filename (-f) or create a header.txt in your working directory." unless File.exists?(header_file_name)
44
-
123
+
45
124
  file = File.new(filename)
46
125
  header = File.new(header_file_name).read
47
-
126
+
48
127
  unless file.nil? || header.nil?
49
128
  str = file.read
50
129
  # Let's remove the magic_encoding at the start, if any.
51
130
  str.gsub!(/^# -\*-.+-\*-(\r)?#{NEWLINE}/, '')
131
+ # quote is optional.
132
+ quote = options[:quote] || ""
133
+ quotestring = ""
134
+ quotestring = "#{NEWLINE}#{quote}#{NEWLINE}#{NEWLINE}" unless quote.eql?("")
52
135
  # and now .. do this.
53
- contents_array = [ BEGIN_HEADER, NEWLINE, header, END_HEADER, NEWLINE ]
54
- # behavior of to_s changed from Ruby 1.8.7 to 1.9.3,
55
- # used to be [ "foo", "bar" ].to_s # => "foobar" <--- 1.8.7
56
- # now it's => "[\"foo\", \"bar\"]" # 1.9.3
57
- #contents_str = contents_array.to_s
58
- contents_str = contents_array.join
136
+ contents_array = [BEGIN_HEADER, NEWLINE, header, quotestring, END_HEADER, NEWLINE]
137
+ # behavior of to_s changed from Ruby 1.8.7 to 1.9.3,
138
+ # used to be [ "foo", "bar" ].to_s # => "foobar" <--- 1.8.7
139
+ # now it's => "[\"foo\", \"bar\"]" # 1.9.3
140
+ #contents_str = contents_array.to_s
141
+ contents_str = contents_array.join
59
142
  # Remove the header that was already in place, if any.
60
143
  str.gsub!(/#{BEGIN_HEADER}.*#{END_HEADER}#{NEWLINE}/m, '')
61
144
  # concat it
62
145
  #contents = contents_str + str
63
- contents = "#{contents_str}#{str}"
146
+ contents = "#{contents_str}#{str}"
64
147
  # Re-open file and write to it
65
148
  file.close
66
149
  file = File.new(filename, 'w')
@@ -71,7 +154,7 @@ module SuperStamper
71
154
  # Return it
72
155
  ret = file
73
156
  end
74
-
157
+
75
158
  ret
76
159
  end
77
160
  end
@@ -1,3 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ###############################################################################
4
+ # super_stamper, a nifty tool that puts headers in all your source files.
5
+ # It does exactly what you see here: a header.txt file is pasted into every .rb file.
6
+ # Also, some random quotes can be added just for kicks.
7
+ #
8
+ # Protip: also install the magic_encoding gem alongside to use it like this:
9
+ # $ super_stamper -q && magic_encoding
10
+ #
11
+ # (c) 2012 Commander Johnson
12
+ # Licensed under the MIT license
13
+ ###############################################################################
14
+
15
+ #<Goatroper> so i had a checkup at the doctor a couple months ago
16
+ #<Goatroper> i waited in the goddamn lobby for like 2 hours
17
+ #<Goatroper> i was just starting to doze off when they called me back into one of the exam rooms
18
+ #<Goatroper> so i sit on this chair for like 30 more mins, and then fall asleep
19
+ #<Goatroper> i wake up and have no idea what time it is or how long i've been waiting
20
+ #<Goatroper> so 20 minutes later after I finished reading the Hispanic Business Weekly
21
+ #<Goatroper> I start diggin through the drawers in the exam table and his desk drawer
22
+ #<Goatroper> i find some hypos and don't touch them, some dressing gowns, and then i get to the drawer marked "OB/GYN"
23
+ #<Goatroper> i open it up, take a peeky-peek inside, and what do I see? Speculums and rectal dilators.
24
+ #<Goatroper> At this point I'm in his desk rolly-chair
25
+ #<Goatroper> with about 40 rubber gloves in my pockets for later use
26
+ #<Goatroper> so I grab a speculum in each hand
27
+ #<Goatroper> and start making them sing and talk like little ducks
28
+ #<Goatroper> i was rooting around for a sharpie and couldn't find one
29
+ #<Goatroper> so i put them down and did my glove-trick
30
+ #<Goatroper> i stretched a rubber glove over my head and blew it up
31
+ #<Goatroper> then i grabbbed the speculums and started spinning around in his chair
32
+ #<Goatroper> glove inflated on my head the size of two basketballs
33
+ #<Goatroper> speculum in each hand
34
+ #<Goatroper> spinning in his office chair
35
+ #<Goatroper> i hear footsteps and as i'm extending my legs to slow down, the door opens
36
+ #<Goatroper> the doctor is standing there with my chart in his hand
37
+ #<kr0nus> omg
38
+ #<Goatroper> i stopped spinning and just sat there, looking at him through the thin film of the glove
39
+ #<Goatroper> he was like "Corey.....?"
40
+ #<Goatroper> I said "Yep."
41
+ #<Goatroper> held up the speculums.
42
+ #<Goatroper> said, "I got bored."
43
+ #<Goatroper> and he was like "That's quite a trick with those gloves. Where did you learn that?"
44
+ #<Goatroper> I said "Many doctor's offices in many states."
45
+ #<Goatroper> He was like "You want to take some with you?" as I got up
46
+ #<Goatroper> I pulled the wad out of my pocket and said "Already did."
47
+ #<Goatroper> then I walked out and i heard him laughing like a goddamn maniac as soon as the door was closed
48
+ #<Goatroper> then the other day i go in again rofl and he just hands me a brand new unopened box of 100 gloves
49
+ #<Goatroper> i was gonna ask for some speculums just to fuck with him but I was afraid he'd give me some
50
+ # -- end header --
1
51
  require 'optparse'
2
52
 
3
53
  module SuperStamper
@@ -5,13 +55,14 @@ module SuperStamper
5
55
  def self.execute(stdout, arguments=[])
6
56
 
7
57
  options = {
8
- :filename => 'header.txt',
9
- :extension => 'rb'
58
+ :filename => 'header.txt',
59
+ :extension => 'rb',
60
+ :quote => false
10
61
  }
11
62
  mandatory_options = %w( )
12
63
 
13
64
  parser = OptionParser.new do |opts|
14
- opts.banner = <<-BANNER.gsub(/^ /,'')
65
+ opts.banner = <<-BANNER.gsub(/^ /, '')
15
66
  Easily add a header (such as a copyright notice or license) recursively to multiple files in your project directory.
16
67
 
17
68
  Usage: #{File.basename($0)} [options]
@@ -21,15 +72,19 @@ module SuperStamper
21
72
  opts.separator ""
22
73
  ########################################################################
23
74
  opts.on("-e", "--extension PATH", String,
24
- "Which extension to look for.",
25
- "Default: rb") { |arg| options[:extension] = arg }
75
+ "Which extension to look for.",
76
+ "Default: rb") { |arg| options[:extension] = arg }
26
77
  ########################################################################
27
78
  opts.on("-f", "--filename PATH", String,
28
- "Which file to use as header.",
29
- "Default: header.txt") { |arg| options[:filename] = arg }
79
+ "Which file to use as header.",
80
+ "Default: header.txt") { |arg| options[:filename] = arg }
81
+ ########################################################################
82
+ opts.on("-q", "--[no-]quote", "Adds a random quote from the Bash.org QDB. Uses your Internet connection to obtain the quotes from the QDB RSS feed.") do |q|
83
+ options[:quote] = q
84
+ end
30
85
  ########################################################################
31
86
  opts.on("-h", "--help",
32
- "Show this help message.") { stdout.puts opts; exit }
87
+ "Show this help message.") { stdout.puts opts; exit }
33
88
  ########################################################################
34
89
  opts.on("-v", "--version", "Print version (#{SuperStamper::VERSION})") { stdout.puts "#{SuperStamper::VERSION}"; exit }
35
90
  opts.parse!(arguments)
@@ -41,8 +96,9 @@ module SuperStamper
41
96
 
42
97
  filename = options[:filename]
43
98
  extension = options[:extension]
44
-
45
- SuperStamper::Base.stamp_recursively( :header_file_name => filename, :extension => extension )
99
+ quote = options[:quote]
100
+
101
+ SuperStamper::Base.stamp_recursively(:header_file_name => filename, :extension => extension, :quote => quote)
46
102
  end
47
103
  end
48
- end
104
+ end
data/script/console CHANGED
File without changes
data/script/destroy CHANGED
File without changes
data/script/generate CHANGED
File without changes
data/test/test_helper.rb CHANGED
@@ -1,3 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ###############################################################################
4
+ # super_stamper, a nifty tool that puts headers in all your source files.
5
+ # It does exactly what you see here: a header.txt file is pasted into every .rb file.
6
+ # Also, some random quotes can be added just for kicks.
7
+ #
8
+ # Protip: also install the magic_encoding gem alongside to use it like this:
9
+ # $ super_stamper -q && magic_encoding
10
+ #
11
+ # (c) 2012 Commander Johnson
12
+ # Licensed under the MIT license
13
+ ###############################################################################
14
+
15
+ #SergioThree: there's other fish in the sea, man, she's just a girl
16
+ #Beatsfromkorea: no dude, that's bullshit.
17
+ #Beatsfromkorea: Think of it this way. if your precious copy of street fighter third strike broke and i told you "it's ok man, there's other games in the sea. here, play mortal kombat instead" what would you say? you'd be like, "fuck that, gimme third strike."
18
+ #SergioThree: ...
19
+ #SergioThree: you just reached me on a level that i never thought possible
20
+ # -- end header --
1
21
  require 'stringio'
2
22
  require 'test/unit'
3
23
  require File.dirname(__FILE__) + '/../lib/super_stamper'
@@ -1,3 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ###############################################################################
4
+ # super_stamper, a nifty tool that puts headers in all your source files.
5
+ # It does exactly what you see here: a header.txt file is pasted into every .rb file.
6
+ # Also, some random quotes can be added just for kicks.
7
+ #
8
+ # Protip: also install the magic_encoding gem alongside to use it like this:
9
+ # $ super_stamper -q && magic_encoding
10
+ #
11
+ # (c) 2012 Commander Johnson
12
+ # Licensed under the MIT license
13
+ ###############################################################################
14
+
15
+ #<DaZE> at my school.. the cop from DARE passed around 3 joints to show everyone... and he said "if i dont get all three of these back this schools getting locked down and everyones getting searched till i find it.." and like 30 minutes later when everyone got to see 'em and they got passed back the cop had 4
16
+ # -- end header --
1
17
  require File.dirname(__FILE__) + '/test_helper.rb'
2
18
 
3
19
  require 'fileutils'
@@ -1,3 +1,38 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ###############################################################################
4
+ # super_stamper, a nifty tool that puts headers in all your source files.
5
+ # It does exactly what you see here: a header.txt file is pasted into every .rb file.
6
+ # Also, some random quotes can be added just for kicks.
7
+ #
8
+ # Protip: also install the magic_encoding gem alongside to use it like this:
9
+ # $ super_stamper -q && magic_encoding
10
+ #
11
+ # (c) 2012 Commander Johnson
12
+ # Licensed under the MIT license
13
+ ###############################################################################
14
+
15
+ #<Montana> yeh but chinese for dinner.. Peking Dick FTW
16
+ #<Dauntless> ... LOL
17
+ #<Montana> omg here we go
18
+ #<Dauntless> Can you say bash.org?
19
+ #<Montana> why? so it can join the other 1 million quotes of random people saying 'i love wang.. oops typo, i meant computers.
20
+ #<Montana> Screw this
21
+ #<Montana> If i'm getting quoted I'm getting my moneys worth:
22
+ #<Montana> MONTY PRESENTS THE ULTIMATE QUOTE
23
+ #<Montana> OMFG my naked sister just ran into my room and before I could sex her she set fire/other means of destruction to my room but because Im a total geek it doesnt occur to me to get of irc and fix it.
24
+ #<Montana> I instead enter a conversation on computers: OMG MY COMPUTER HAS GOT A VIRUS! OH WAIT NO, ITS WINDOWS/LINUX/MAC/NORTON/AOL. Now for the obligatory Windows ME insult where the name of the product is mistaken for a pronoun for myself:
25
+ #<Montana> ME SO GAY! WHOOPS IT LOOKS LIKE THE INTENDED PURPOSE OF THAT STATEMENT WAS TO HIGHLIGHT MY OWN HOMOSEXUALITY WHEREAS I MEANT IT TO BE THE HOMOSEXUALITY OF THE OPERATING SYSTEM! HOW EMBARASSING!
26
+ #<Montana> Now for the topic of sex:
27
+ #<Montana> I HAVE A GF.. AND BY GF I OF COURSE MEAN A GFORCE 20MB 3.45 SYSTEM RETRO POWER MAX SUPERMAN RAPING COMPUTER STICK!
28
+ #<Montana> Furthermore, I make a comment as to the worth of sex but comment of my lack of sexual activity.
29
+ #<Montana> Hmm
30
+ #<Montana> I'm forgetting the most impostant part! The lack of social interaction!
31
+ #<Montana> OMG I just opened my blinds and the sunlight burnt and I saw this guy with a swollen chest and I was like WTF and my dad says 'thats called a girl' im like WTF IS A GIRL then i went and downloaded 50GB of porn.
32
+ #<Montana> </end rant>
33
+ #<Montana> Anyways, as I said before.. dinner.. brb
34
+ #<Dauntless> o_o
35
+ # -- end header --
1
36
  require File.join(File.dirname(__FILE__), "test_helper.rb")
2
37
  require 'super_stamper/cli'
3
38
 
@@ -11,4 +46,4 @@ class TestSuperStamperCli < Test::Unit::TestCase
11
46
  # def test_print_default_output
12
47
  # assert_match(/To update this executable/, @stdout)
13
48
  # end
14
- end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_stamper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-10-19 00:00:00.000000000 Z
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '3.1'
53
+ version: '3.3'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '3.1'
61
+ version: '3.3'
62
62
  description: Easily add a header (such as a copyright notice or license) recursively
63
63
  to multiple files in your project directory.
64
64
  email: