einfug 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/einfug +24 -0
  2. data/lib/einfug.rb +33 -0
  3. metadata +70 -0
data/bin/einfug ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'einfug'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: einfug files|directories"
11
+
12
+ opts.on('-r', '--recursive', 'If a directory is given as parameter, going recursively through it, putting all files.') do
13
+ options[:r] = true
14
+ end
15
+
16
+ opts.on('-f', '--full', 'Putting absolute paths instead of filenames as section titles.') do
17
+ options[:f] = true
18
+ end
19
+ end.parse!
20
+
21
+ ARGV.each do |path|
22
+ puts Pathname.new(path).to_pastie(options[:r], options[:f])
23
+ end
24
+
data/lib/einfug.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'pathname'
2
+
3
+ class Pathname
4
+ def to_pastie(recursive = false, full = false)
5
+ if self.file?
6
+ return pastie(self, full)
7
+ elsif self.directory?
8
+ pathnames = []
9
+ bad_paths = [Pathname.new('.'), Pathname.new('..')]
10
+
11
+ self.children.each do |pathname|
12
+ if recursive
13
+ pathnames << pathname unless bad_paths.include?(pathname)
14
+ elsif pathname.file?
15
+ pathnames << pathname
16
+ end
17
+ end
18
+
19
+ return pathnames.map { |pathname| pathname.to_pastie(recursive, full) }.join("\n")
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def pastie(file, full = false)
26
+ path = full ? file.realpath : file.basename
27
+ section = "## "
28
+ content = File.read(file).sub(/(\r|\n)+\z/, '')
29
+
30
+ return "#{section}#{path}\n#{content}"
31
+ end
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: einfug
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Tobias B\xC3\xBChlmann"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-24 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Transform files and directories in a pastable form
23
+ email: tobias.buehlmann@gmx.de
24
+ executables:
25
+ - einfug
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - bin/einfug
32
+ - lib/einfug.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/tbuehlmann/einfug
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 59
48
+ segments:
49
+ - 1
50
+ - 8
51
+ - 6
52
+ version: 1.8.6
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Pastie helper
69
+ test_files: []
70
+