grinc 0.1.0

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,32 @@
1
+ # Grizzled Ruby
2
+
3
+ ## Intro
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.
10
+
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'
28
+
29
+ ## Copyright and License
30
+
31
+ This code is copyright © 2011 Brian M. Clapper and is released under a
32
+ BSD License.
@@ -0,0 +1,143 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # NOTE: Man pages use the 'ronn' gem. http://rtomayko.github.com/ronn/
4
+
5
+ require 'rake/clean'
6
+ require 'pathname'
7
+
8
+ PACKAGE = 'grinc'
9
+ GEMSPEC = "#{PACKAGE}.gemspec"
10
+ RUBY_FILES = FileList['bin/*']
11
+ MAN_OUT_DIR = 'man'
12
+ GH_PAGES_DIR = File.join('..', 'gh-pages')
13
+ MAN_PUBLISH_DIR = File.join(GH_PAGES_DIR, 'man')
14
+ MAN_SOURCE_DIR = 'src-man'
15
+ MAN_SOURCES = FileList[File.join(MAN_SOURCE_DIR, '*.md')]
16
+
17
+ MAN_PAGES = MAN_SOURCES.map do |m|
18
+ if m =~ %r{#{MAN_SOURCE_DIR}/([^.]+)\.([0-9])\.md$}
19
+ [File.join(MAN_OUT_DIR, "man#{$2}", "#{$1}.#{$2}.html"),
20
+ File.join(MAN_OUT_DIR, "man#{$2}", "#{$1}.#{$2}")]
21
+ else
22
+ raise StandardError.new("#{m} doesn't look like a man page source.")
23
+ end
24
+ end.flatten
25
+
26
+ def load_gem(spec)
27
+ eval File.open(spec).readlines.join('')
28
+ end
29
+
30
+ def gem_name(spec)
31
+ gem = load_gem(spec)
32
+ "#{PACKAGE}-#{gem.version.to_s}.gem"
33
+ end
34
+
35
+ GEM = gem_name(GEMSPEC)
36
+ CLEAN << [MAN_OUT_DIR, GEM]
37
+
38
+ # ---------------------------------------------------------------------------
39
+ # Rules
40
+ # ---------------------------------------------------------------------------
41
+
42
+ def man_source
43
+ Proc.new do |man_target|
44
+ if man_target =~ %r{#{MAN_OUT_DIR}/man[0-9]/(.*\.[0-9])}
45
+ File.join("src-man", $1 + ".md")
46
+ elsif man_target =~ %r{#{MAN_OUT_DIR}/man[0-9]/(.*\.[0-9].html)}
47
+ File.join("src-man", $1 + ".md")
48
+ else
49
+ raise StandardError.new("Can't find source for man page #{man_target}")
50
+ end
51
+ end
52
+ end
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
+ # 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|
62
+ mkdir_p File.dirname(t.name)
63
+ sh "ronn --html --pipe #{t.source} >#{t.name}"
64
+ end
65
+
66
+
67
+ # ---------------------------------------------------------------------------
68
+ # Tasks
69
+ # ---------------------------------------------------------------------------
70
+
71
+ task :default => :build
72
+
73
+ desc "Build everything"
74
+ task :build => [:gem, :doc]
75
+
76
+ desc "Synonym for 'build'"
77
+ task :all => :build
78
+
79
+ desc "Build the gem (#{GEM})"
80
+ task :gem => GEM
81
+
82
+ file GEM => RUBY_FILES + ['Rakefile', GEMSPEC] do |t|
83
+ require 'rubygems/builder'
84
+ if !defined? Gem
85
+ raise StandardError.new("Gem package not defined.")
86
+ end
87
+ spec = eval File.new(GEMSPEC).read
88
+ Gem::Builder.new(spec).build
89
+ end
90
+
91
+ desc "Build the documentation, locally"
92
+ task :doc => :man
93
+
94
+ task :man => MAN_PAGES + ['Rakefile']
95
+
96
+ desc "Install the gem"
97
+ task :install => :gem do |t|
98
+ require 'rubygems/installer'
99
+ puts("Installing from #{GEM}")
100
+ Gem::Installer.new(GEM).install
101
+ end
102
+
103
+ desc "Publish the gem"
104
+ task :publish => :gem do |t|
105
+ sh "gem push #{GEM}"
106
+ end
107
+
108
+ desc "Publish the docs. Not really of use to anyone but the author"
109
+ task :pubdoc => [:pubman, :pubchangelog]
110
+
111
+ desc "Publish the man pages. Not really of use to anyone but the author"
112
+ task :pubman => :man do |t|
113
+ target = Pathname.new(MAN_PUBLISH_DIR).expand_path.to_s
114
+ cd MAN_OUT_DIR do
115
+ mkdir_p target
116
+ Dir['*.html'].each do |m|
117
+ cp m, target
118
+ end
119
+ end
120
+ end
121
+
122
+ desc "Synonym for 'pubchangelog'"
123
+ task :changelog
124
+
125
+ desc "Publish the change log. Not really of use to anyone but the author"
126
+ task :pubchangelog do |t|
127
+ File.open(File.join(GH_PAGES_DIR, 'CHANGELOG.md'), 'w') do |f|
128
+ f.write <<EOF
129
+ ---
130
+ title: Change Log for grinc
131
+ layout: default
132
+ ---
133
+
134
+ EOF
135
+ f.write File.open('CHANGELOG.md').read
136
+ f.close
137
+ end
138
+ end
139
+
140
+ task :pub
141
+
142
+ desc "Alias for 'docpub'"
143
+ task :docpub => :pubdoc
@@ -0,0 +1,156 @@
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
+ # ---------------------------------------------------------------------------
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
156
+
@@ -0,0 +1,36 @@
1
+ # -*- ruby -*-
2
+
3
+ Gem::Specification.new do |s|
4
+
5
+ s.name = 'grinc'
6
+ s.version = '0.1.0'
7
+ s.date = '2011-03-25'
8
+ s.summary = 'Command line include file preprocessor'
9
+ s.authors = ['Brian M. Clapper']
10
+ s.license = 'BSD'
11
+ s.email = 'bmc@clapper.org'
12
+ s.homepage = 'http://software.clapper.org/grinc'
13
+ s.has_rdoc = false
14
+
15
+ s.description = <<-ENDDESC
16
+ grinc runs an include file preprocessor on one or more files, writing the
17
+ result to an output file (or standard output).
18
+ ENDDESC
19
+
20
+ s.add_dependency('grizzled-ruby', '>= 0.1.4')
21
+
22
+ # = MANIFEST =
23
+ s.files = Dir.glob('[A-Z]*')
24
+ s.files += Dir.glob('*.gemspec')
25
+ s.files += Dir.glob('lib/**/*')
26
+ s.files += Dir.glob('bin/**/*')
27
+ s.files += Dir.glob('man/**/*.[0-9]')
28
+ s.files += Dir.glob('src-man/**/*')
29
+
30
+
31
+ # = MANIFEST =
32
+ s.executables = ['grinc']
33
+
34
+ end
35
+
36
+
@@ -0,0 +1,79 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "GRINC" "1" "March 2011" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBgrinc\fR \- Process includes on a text file
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBgrinc\fR [\-o output | \-\-output output] [\-n maxnest | \-\-maxnest maxnest] [files]
11
+ .
12
+ .SH "DESCRIPTION"
13
+ \fIgrinc\fR runs an include file preprocessor on one or more files, writing the result to an output file (or standard output)\.
14
+ .
15
+ .P
16
+ If the output file isn\'t specified, output is written to standard output\.
17
+ .
18
+ .P
19
+ The \fIinclude\fR syntax is simple:
20
+ .
21
+ .IP "" 4
22
+ .
23
+ .nf
24
+
25
+ %include "filespec"
26
+ .
27
+ .fi
28
+ .
29
+ .IP "" 0
30
+ .
31
+ .P
32
+ \fIfilespec\fR can be an absolute pathname, a relative pathname, a simple file name, or a URL\. For example:
33
+ .
34
+ .IP "" 4
35
+ .
36
+ .nf
37
+
38
+ %include "/absolute/path/to/file"
39
+ %include "\.\./relative/path/to/file"
40
+ %include "local_reference"
41
+ %include "http://localhost/path/to/my\.config"
42
+ .
43
+ .fi
44
+ .
45
+ .IP "" 0
46
+ .
47
+ .P
48
+ Relative and local file references are relative to the including file or URL\. That, if \fIgrinc\fR is processing file "/home/bmc/foo\.txt" and encounters an attempt to include file "bar\.txt", it will assume "bar\.txt" is to be found in "/home/bmc"\.
49
+ .
50
+ .P
51
+ Similarly, if \fIgrinc\fR is processing URL "http://localhost/bmc/foo\.txt" and encounters an attempt to include file "bar\.txt", it will assume "bar\.txt" is to be found at "http://localhost/bmc/bar\.txt"\.
52
+ .
53
+ .P
54
+ Nested includes are permitted; that is, an included file may, itself, include other files\. The maximum recursion level is configurable, via a command line option, and defaults to 100\.
55
+ .
56
+ .P
57
+ Multiple input files are permitted; they are processed in turn, and their expanded outputs are concatenated to the output file\. If no input files are specified, \fIgrinc\fR reads standard input\.
58
+ .
59
+ .SH "OPTIONS"
60
+ .
61
+ .TP
62
+ \fB\-n N\fR, \fB\-\-nesting=N\fR, \fB\-\-nesting N\fR
63
+ The maximum number of nested include files\. Default: 100
64
+ .
65
+ .TP
66
+ \fB\-o file\fR, \fB\-\-output=file\fR, \fB\-\-output file\fR
67
+ Where to write the resulting expanded file\. Default: standard output\.
68
+ .
69
+ .SH "SEE ALSO"
70
+ m4(1)
71
+ .
72
+ .SH "AUTHOR"
73
+ Brian M\. Clapper, \fIbmc@clapper\.org\fR
74
+ .
75
+ .SH "COPYRIGHT"
76
+ Copyright \(co 2011 Brian M\. Clapper
77
+ .
78
+ .SH "LICENSE"
79
+ \fIgrinc\fR is released under a BSD license\.
@@ -0,0 +1,66 @@
1
+ grinc(1) -- Process includes on a text file
2
+ ===========================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `grinc` [-o output | --output output] [-n maxnest | --maxnest maxnest] [files]
7
+
8
+ ## DESCRIPTION
9
+
10
+ *grinc* runs an include file preprocessor on one or more files, writing the
11
+ result to an output file (or standard output).
12
+
13
+ If the output file isn't specified, output is written to standard output.
14
+
15
+ The *include* syntax is simple:
16
+
17
+ %include "filespec"
18
+
19
+ *filespec* can be an absolute pathname, a relative pathname, a simple file
20
+ name, or a URL. For example:
21
+
22
+ %include "/absolute/path/to/file"
23
+ %include "../relative/path/to/file"
24
+ %include "local_reference"
25
+ %include "http://localhost/path/to/my.config"
26
+
27
+ Relative and local file references are relative to the including file or
28
+ URL. That, if *grinc* is processing file "/home/bmc/foo.txt" and encounters
29
+ an attempt to include file "bar.txt", it will assume "bar.txt" is to be
30
+ found in "/home/bmc".
31
+
32
+ Similarly, if *grinc* is processing URL "http://localhost/bmc/foo.txt" and
33
+ encounters an attempt to include file "bar.txt", it will assume "bar.txt"
34
+ is to be found at "http://localhost/bmc/bar.txt".
35
+
36
+ Nested includes are permitted; that is, an included file may, itself,
37
+ include other files. The maximum recursion level is configurable, via
38
+ a command line option, and defaults to 100.
39
+
40
+ Multiple input files are permitted; they are processed in turn, and their
41
+ expanded outputs are concatenated to the output file. If no input files
42
+ are specified, *grinc* reads standard input.
43
+
44
+ ## OPTIONS
45
+
46
+ * `-n N`, `--nesting=N`, `--nesting N`:
47
+ The maximum number of nested include files. Default: 100
48
+
49
+ * `-o file`, `--output=file`, `--output file`:
50
+ Where to write the resulting expanded file. Default: standard output.
51
+
52
+ ## SEE ALSO
53
+
54
+ m4(1)
55
+
56
+ ## AUTHOR
57
+
58
+ Brian M. Clapper, [bmc@clapper.org](bmc@clapper.org)
59
+
60
+ ## COPYRIGHT
61
+
62
+ Copyright &copy; 2011 Brian M. Clapper
63
+
64
+ ## LICENSE
65
+
66
+ *grinc* is released under a BSD license.
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grinc
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Brian M. Clapper
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-25 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: grizzled-ruby
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 4
34
+ version: 0.1.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: |
38
+ grinc runs an include file preprocessor on one or more files, writing the
39
+ result to an output file (or standard output).
40
+
41
+ email: bmc@clapper.org
42
+ executables:
43
+ - grinc
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - README.md
50
+ - Rakefile
51
+ - grinc.gemspec
52
+ - bin/grinc
53
+ - man/man1/grinc.1
54
+ - src-man/grinc.1.md
55
+ has_rdoc: true
56
+ homepage: http://software.clapper.org/grinc
57
+ licenses:
58
+ - BSD
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.5.0
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Command line include file preprocessor
89
+ test_files: []
90
+