opus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +4 -0
  2. data/bin/opus +32 -0
  3. data/lib/opus.rb +50 -0
  4. data/lib/opus/version.rb +3 -0
  5. metadata +136 -0
@@ -0,0 +1,4 @@
1
+ # Opus
2
+ > Command line utility for printing columnized code.
3
+
4
+ -----
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib'))
4
+
5
+ require 'rubygems'
6
+ require 'opus'
7
+ require 'commander/import'
8
+
9
+ program :name, 'Opus'
10
+ program :version, Opus::VERSION
11
+ program :description, 'Command line utility for printing columnized code.'
12
+ default_command :generate
13
+
14
+ command :generate do |c|
15
+ c.syntax = 'opus generate FILE'
16
+ c.description = 'Generates a PDF from a list of source files.'
17
+ c.option '-c NUM', '--columns NUM', 'The number of columns per page.'
18
+ c.option '-o FILE', '--output FILE', 'The name of the output file.'
19
+ c.when_called do|args, options|
20
+ filenames = args
21
+ output = options.output
22
+
23
+ # Validate input.
24
+ abort("opus: one or more input files required") if filenames.empty?
25
+ abort("opus: output file required: --output") if options.output.nil?
26
+
27
+ # Generate the PDF.
28
+ opus = Opus.new()
29
+ opus.column_count = options.columns.to_i unless options.columns.nil?
30
+ opus.generate(filenames, output)
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'opus/version'
4
+ require 'prawn'
5
+
6
+ class Opus
7
+ # Creates a new opus instance.
8
+ def initialize()
9
+ self.page_layout = :landscape
10
+ self.column_count = 5
11
+ self.font_family = "Courier"
12
+ self.font_size = 4
13
+ end
14
+
15
+ # The number of columns per page.
16
+ attr_accessor :column_count
17
+
18
+ # The font family to use.
19
+ attr_accessor :font_family
20
+
21
+ # The font size to use.
22
+ attr_accessor :font_size
23
+
24
+ # The page layout to use (portrait, landscape).
25
+ attr_accessor :page_layout
26
+
27
+ # Generates a PDF from a list of source files.
28
+ #
29
+ # @param filenames [Array] a list of input files.
30
+ # @param output [IO] the destination for the PDF output.
31
+ def generate(filenames, output)
32
+ column_count = self.column_count
33
+ font_family = self.font_family
34
+ font_size = self.font_size
35
+
36
+ # Columnize lines in PDF.
37
+ Prawn::Document.generate(output, page_layout: page_layout) do
38
+ font(font_family, :size => font_size) do
39
+ column_box([0, cursor], :columns => column_count, :width => bounds.width) do
40
+ filenames.each do |filename|
41
+ content = IO.read(filename).gsub(/^/, ". ")
42
+ text("<b>#{filename}</b>", inline_format: true)
43
+ text(content)
44
+ text("\n\n")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ class Opus
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: prawn
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.13.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.13.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: commander
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 4.1.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 4.1.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.0.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 5.2.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 5.2.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.14.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.14.0
94
+ description:
95
+ email:
96
+ - benbjohnson@yahoo.com
97
+ executables:
98
+ - opus
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - lib/opus/version.rb
103
+ - lib/opus.rb
104
+ - README.md
105
+ - bin/opus
106
+ homepage: http://github.com/benbjohnson/opus
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -334966235729417994
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -334966235729417994
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 1.8.25
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Command line utility for printing columnized code.
136
+ test_files: []