grinc 0.1.0 → 0.1.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.
@@ -0,0 +1,13 @@
1
+ # Change Log for grinc
2
+
3
+ Version 0.1.1
4
+
5
+ - Rearranged code include command runner and library. Keeps rdoc happier,
6
+ anyway.
7
+ - Fixed "install" rake task.
8
+
9
+ ----
10
+
11
+ Version 0.1.0 (25 March, 2011)
12
+
13
+ - Moved *grinc* to its own gem and repo, from Grizzled Ruby, and published it.
data/README.md CHANGED
@@ -1,32 +1,18 @@
1
- # Grizzled Ruby
1
+ # grinc
2
2
 
3
3
  ## Intro
4
4
 
5
- The Grizzled Ruby Utility Library is a general-purpose Ruby library
6
- with a variety of different modules and classes. Basically, it's an
7
- organized dumping ground for various useful APIs I find I need. It's
8
- similar, in concept, to my [Grizzled Python][] and [Grizzled Scala][]
9
- libraries, for [Python][] and [Scala][], respectively.
5
+ *grinc* runs an include file preprocessor on one or more files, writing the
6
+ result to an output file (or standard output). It uses the
7
+ `Grizzled::FileUtil::Includer` class in the [Grizzled Ruby][] gem.
10
8
 
11
- It can be built as a gem, but the gem isn't (yet) public.
12
-
13
- [Grizzled Python]: http://software.clapper.org/grizzled/
14
- [Grizzled Scala]: http://software.clapper.org/grizzled-scala/
15
- [Scala]: http://www.scala-lang.org/
16
- [Python]: http://www.python.org/
17
-
18
- ## To build
19
-
20
- $ git clone git://github.com/bmc/grizzled-ruby.git
21
- $ cd grizzled-ruby
22
- $ gem build grizzled-ruby.gemspec
23
- $ gem install grizzled-ruby
24
-
25
- ## To use in your code
26
-
27
- require 'grizzled'
9
+ For installation instructions and additional documentation, see the
10
+ [*grinc* web page][].
28
11
 
29
12
  ## Copyright and License
30
13
 
31
14
  This code is copyright © 2011 Brian M. Clapper and is released under a
32
15
  BSD License.
16
+
17
+ [*grinc* web page]: http://software.clapper.org/grinc/
18
+ [Grizzled Ruby]: http://software.clapper.org/grizzled-ruby/
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'pathname'
7
7
 
8
8
  PACKAGE = 'grinc'
9
9
  GEMSPEC = "#{PACKAGE}.gemspec"
10
- RUBY_FILES = FileList['bin/*']
10
+ RUBY_FILES = FileList['bin/*', 'lib/*']
11
11
  MAN_OUT_DIR = 'man'
12
12
  GH_PAGES_DIR = File.join('..', 'gh-pages')
13
13
  MAN_PUBLISH_DIR = File.join(GH_PAGES_DIR, 'man')
@@ -33,7 +33,7 @@ def gem_name(spec)
33
33
  end
34
34
 
35
35
  GEM = gem_name(GEMSPEC)
36
- CLEAN << [MAN_OUT_DIR, GEM]
36
+ CLEAN << [MAN_OUT_DIR] + FileList['*.gem']
37
37
 
38
38
  # ---------------------------------------------------------------------------
39
39
  # Rules
@@ -51,18 +51,17 @@ def man_source
51
51
  end
52
52
  end
53
53
 
54
- # Make man/man?/thing.? from src-man/thing.?/md
55
- rule %r{#{MAN_OUT_DIR}/man[0-9]/.*\.[0-9]} => [man_source, 'Rakefile'] do |t|
56
- mkdir_p File.dirname(t.name)
57
- sh "ronn --roff --pipe #{t.source} >#{t.name}"
58
- end
59
-
60
54
  # Make man/man?/thing.?.html from src-man/thing.?/md
61
- rule %r{#{MAN_OUT_DIR}/man[0-9]/.*\.[0-9]\.html} => [man_source, 'Rakefile'] do |t|
55
+ rule %r{#{MAN_OUT_DIR}/man[0-9]/[^.]+\.[0-9]\.html} => [man_source, 'Rakefile'] do |t|
62
56
  mkdir_p File.dirname(t.name)
63
57
  sh "ronn --html --pipe #{t.source} >#{t.name}"
64
58
  end
65
59
 
60
+ # Make man/man?/thing.? from src-man/thing.?/md
61
+ rule %r{#{MAN_OUT_DIR}/man[0-9]/[^.]+\.[0-9]} => [man_source, 'Rakefile'] do |t|
62
+ mkdir_p File.dirname(t.name)
63
+ sh "ronn --roff --pipe #{t.source} >#{t.name}"
64
+ end
66
65
 
67
66
  # ---------------------------------------------------------------------------
68
67
  # Tasks
@@ -77,7 +76,7 @@ desc "Synonym for 'build'"
77
76
  task :all => :build
78
77
 
79
78
  desc "Build the gem (#{GEM})"
80
- task :gem => GEM
79
+ task :gem => [GEM, :doc]
81
80
 
82
81
  file GEM => RUBY_FILES + ['Rakefile', GEMSPEC] do |t|
83
82
  require 'rubygems/builder'
@@ -95,9 +94,8 @@ task :man => MAN_PAGES + ['Rakefile']
95
94
 
96
95
  desc "Install the gem"
97
96
  task :install => :gem do |t|
98
- require 'rubygems/installer'
99
97
  puts("Installing from #{GEM}")
100
- Gem::Installer.new(GEM).install
98
+ sh "gem install #{GEM}"
101
99
  end
102
100
 
103
101
  desc "Publish the gem"
@@ -110,10 +108,11 @@ task :pubdoc => [:pubman, :pubchangelog]
110
108
 
111
109
  desc "Publish the man pages. Not really of use to anyone but the author"
112
110
  task :pubman => :man do |t|
113
- target = Pathname.new(MAN_PUBLISH_DIR).expand_path.to_s
111
+ target_dir = Pathname.new(MAN_PUBLISH_DIR).expand_path.to_s
114
112
  cd MAN_OUT_DIR do
115
- mkdir_p target
116
- Dir['*.html'].each do |m|
113
+ mkdir_p target_dir
114
+ Dir['**/*.html'].each do |m|
115
+ target = File.join(target_dir, File.basename(m))
117
116
  cp m, target
118
117
  end
119
118
  end
data/bin/grinc CHANGED
@@ -37,120 +37,7 @@
37
37
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
38
  #++
39
39
 
40
- require 'optparse'
41
40
  require 'rubygems'
42
- require 'grizzled/fileutil/includer'
43
-
44
- include Grizzled::FileUtil
45
-
46
- # ---------------------------------------------------------------------------
47
- # Constants
48
- # ---------------------------------------------------------------------------
49
-
50
- DEFAULT_MAX_NEST = 100
51
- PROGRAM_NAME = 'grinc'
52
-
53
- # ---------------------------------------------------------------------------
54
- # Classes
55
- # ---------------------------------------------------------------------------
56
-
57
- class Parameters
58
- attr_reader :output, :max_nesting, :input_paths
59
-
60
- def initialize(options_hash, argv)
61
- @output = options_hash[:output]
62
- @max_nesting = options_hash[:max_nesting] || DEFAULT_MAX_NEST
63
- @input_paths = argv.length == 0 ? nil : argv
64
- end
65
-
66
- def to_s
67
- inspect
68
- end
69
- end
70
-
71
- class UsageError < StandardError; end
72
-
73
- # ---------------------------------------------------------------------------
74
- # Parameter parsing
75
- # ---------------------------------------------------------------------------
76
-
77
- def parse_params
78
- options_hash = {}
79
- error = nil
80
- option_parser = OptionParser.new do |opts|
81
- opts.program_name = PROGRAM_NAME
82
- opts.banner = "Usage: #{opts.program_name} [OPTIONS] inputfile ..."
83
- opts.separator ''
84
- opts.separator 'OPTIONS:'
85
-
86
- opts.on('-o FILE', 'Output file. Default: standard output.') do |f|
87
- options_hash[:output] = f
88
- end
89
-
90
- opts.on('-n', '--nesting n',
91
- "Max nesting. Default: #{DEFAULT_MAX_NEST}") do |n|
92
- if n !~ /^[0-9]+$/
93
- error = "Non-numeric parameter \"#{n}\" to -n option."
94
- end
95
- options_hash[:max_nesting] = n.to_i
96
- end
97
- end
98
-
99
- begin
100
- option_parser.parse!(ARGV)
101
- rescue OptionParser::InvalidOption => ex
102
- error = ex.to_s
103
- end
104
-
105
- if error
106
- $stderr.puts(error) unless error.nil?
107
- option_parser.display
108
- raise UsageError.new
109
- end
110
-
111
- if ARGV.length == 0
112
- options_hash[:input_files] = nil
113
- else
114
- options_hash[:input_files] = ARGV
115
- end
116
-
117
- Parameters.new(options_hash, ARGV)
118
- end
119
-
120
- def process_include(input_file, output_file, max_nesting = 100)
121
- Includer.new(input_file, :max_nesting => max_nesting).each do |line|
122
- output_file.write(line)
123
- end
124
- end
125
-
126
- # ---------------------------------------------------------------------------
127
- # Main logic
128
- # ---------------------------------------------------------------------------
129
-
130
- begin
131
- params = parse_params
132
- out = params.output.nil? ? $stderr : File.open(params.output, 'w')
133
-
134
- if params.input_paths.nil?
135
- process_include($stdin, out, params.max_nesting)
136
- else
137
- params.input_paths.each do |f|
138
- process_include(File.open(f), out, params.max_nesting)
139
- end
140
- end
141
-
142
- rescue UsageError
143
- exit 1
144
-
145
- rescue Interrupt
146
- $stderr.puts("\nAborted")
147
- exit 1
148
-
149
- rescue
150
- $stderr.puts("#{PROGRAM_NAME}: #{$!}")
151
- exit 1
152
-
153
- else
154
- exit 0
155
- end
41
+ require 'grizzled/grinc'
156
42
 
43
+ exit Grizzled::Grinc::GrincRunner.new.run
@@ -3,14 +3,13 @@
3
3
  Gem::Specification.new do |s|
4
4
 
5
5
  s.name = 'grinc'
6
- s.version = '0.1.0'
7
- s.date = '2011-03-25'
6
+ s.version = '0.1.1'
7
+ s.date = '2011-03-26'
8
8
  s.summary = 'Command line include file preprocessor'
9
9
  s.authors = ['Brian M. Clapper']
10
10
  s.license = 'BSD'
11
11
  s.email = 'bmc@clapper.org'
12
12
  s.homepage = 'http://software.clapper.org/grinc'
13
- s.has_rdoc = false
14
13
 
15
14
  s.description = <<-ENDDESC
16
15
  grinc runs an include file preprocessor on one or more files, writing the
@@ -22,8 +21,8 @@ ENDDESC
22
21
  # = MANIFEST =
23
22
  s.files = Dir.glob('[A-Z]*')
24
23
  s.files += Dir.glob('*.gemspec')
25
- s.files += Dir.glob('lib/**/*')
26
24
  s.files += Dir.glob('bin/**/*')
25
+ s.files += Dir.glob('lib/**/*')
27
26
  s.files += Dir.glob('man/**/*.[0-9]')
28
27
  s.files += Dir.glob('src-man/**/*')
29
28
 
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # See the man page or http://software.clapper.org/grizzled-ruby/grinc/
4
+ # for documentation.
5
+ #--
6
+ # This software is released under a BSD license, adapted from
7
+ # http://opensource.org/licenses/bsd-license.php
8
+ #
9
+ # Copyright (c) 2011, Brian M. Clapper
10
+ # All rights reserved.
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are
14
+ # met:
15
+ #
16
+ # * Redistributions of source code must retain the above copyright notice,
17
+ # this list of conditions and the following disclaimer.
18
+ #
19
+ # * Redistributions in binary form must reproduce the above copyright
20
+ # notice, this list of conditions and the following disclaimer in the
21
+ # documentation and/or other materials provided with the distribution.
22
+ #
23
+ # * Neither the names "clapper.org", "Grizzled Ruby Library", nor the
24
+ # names of its contributors may be used to endorse or promote products
25
+ # derived from this software without specific prior written permission.
26
+ #
27
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+ #++
39
+
40
+ require 'optparse'
41
+ require 'rubygems'
42
+ require 'grizzled/fileutil/includer'
43
+
44
+ include Grizzled::FileUtil
45
+
46
+ module Grizzled
47
+
48
+ module Grinc
49
+
50
+ # -----------------------------------------------------------------------
51
+ # Constants
52
+ # -----------------------------------------------------------------------
53
+
54
+ DEFAULT_MAX_NEST = 100
55
+ PROGRAM_NAME = 'grinc'
56
+
57
+ # -----------------------------------------------------------------------
58
+ # Classes
59
+ # -----------------------------------------------------------------------
60
+
61
+ class Parameters
62
+ attr_reader :output, :max_nesting, :input_paths
63
+
64
+ def initialize(options_hash, argv)
65
+ @output = options_hash[:output]
66
+ @max_nesting = options_hash[:max_nesting] || DEFAULT_MAX_NEST
67
+ @input_paths = argv.length == 0 ? nil : argv
68
+ end
69
+
70
+ def to_s
71
+ inspect
72
+ end
73
+ end
74
+
75
+ class UsageError < StandardError; end
76
+
77
+ class GrincRunner
78
+ def initialize
79
+ end
80
+
81
+ def run
82
+ begin
83
+ params = parse_params
84
+ out = params.output.nil? ? $stderr : File.open(params.output, 'w')
85
+
86
+ if params.input_paths.nil?
87
+ process_include($stdin, out, params.max_nesting)
88
+ else
89
+ params.input_paths.each do |f|
90
+ process_include(File.open(f), out, params.max_nesting)
91
+ end
92
+ end
93
+
94
+ rescue UsageError
95
+ return 1
96
+
97
+ rescue Interrupt
98
+ $stderr.puts("\nAborted")
99
+ return 1
100
+
101
+ rescue
102
+ $stderr.puts("#{PROGRAM_NAME}: #{$!}")
103
+ return 1
104
+
105
+ else
106
+ return 0
107
+ end
108
+ end
109
+
110
+ def parse_params
111
+ options_hash = {}
112
+ error = nil
113
+ option_parser = OptionParser.new do |opts|
114
+ opts.program_name = PROGRAM_NAME
115
+ opts.banner = "Usage: #{opts.program_name} [OPTIONS] inputfile ..."
116
+ opts.separator ''
117
+ opts.separator 'OPTIONS:'
118
+
119
+ opts.on('-o FILE', 'Output file. Default: standard output.') do |f|
120
+ options_hash[:output] = f
121
+ end
122
+
123
+ opts.on('-n', '--nesting n',
124
+ "Max nesting. Default: #{DEFAULT_MAX_NEST}") do |n|
125
+ if n !~ /^[0-9]+$/
126
+ error = "Non-numeric parameter \"#{n}\" to -n option."
127
+ end
128
+ options_hash[:max_nesting] = n.to_i
129
+ end
130
+ end
131
+
132
+ begin
133
+ option_parser.parse!(ARGV)
134
+ rescue OptionParser::InvalidOption => ex
135
+ error = ex.to_s
136
+ end
137
+
138
+ if error
139
+ $stderr.puts(error) unless error.nil?
140
+ option_parser.display
141
+ raise UsageError.new
142
+ end
143
+
144
+ if ARGV.length == 0
145
+ options_hash[:input_files] = nil
146
+ else
147
+ options_hash[:input_files] = ARGV
148
+ end
149
+
150
+ Parameters.new(options_hash, ARGV)
151
+ end
152
+
153
+ private
154
+
155
+ def process_include(input_file, output_file, max_nesting = 100)
156
+ Includer.new(input_file, :max_nesting => max_nesting).each do |line|
157
+ output_file.write(line)
158
+ end
159
+ end
160
+ end
161
+
162
+ end # module Grinc
163
+ end # module Grizzled
164
+
165
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grinc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian M. Clapper
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-25 00:00:00 -04:00
18
+ date: 2011-03-26 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,10 +46,12 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
 
48
48
  files:
49
- - README.md
49
+ - CHANGELOG.md
50
50
  - Rakefile
51
+ - README.md
51
52
  - grinc.gemspec
52
53
  - bin/grinc
54
+ - lib/grizzled/grinc.rb
53
55
  - man/man1/grinc.1
54
56
  - src-man/grinc.1.md
55
57
  has_rdoc: true
@@ -82,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
84
  requirements: []
83
85
 
84
86
  rubyforge_project:
85
- rubygems_version: 1.5.0
87
+ rubygems_version: 1.6.2
86
88
  signing_key:
87
89
  specification_version: 3
88
90
  summary: Command line include file preprocessor