processr 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Josh Nesbitt <josh@josh-nesbitt.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "processr"
8
+ gem.summary = "A simple text processing library"
9
+ gem.description = "Processr provides a really simple interface to processing a set of text files. Through the use of filters you can further modify output before writing the contents to a file."
10
+ gem.email = "josh@josh-nesbitt.net"
11
+ gem.homepage = "http://github.com/joshnesbitt/processr"
12
+ gem.authors = ["Josh Nesbitt"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+ task :default => :spec
34
+
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rdoc|
37
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
38
+
39
+ rdoc.rdoc_dir = 'rdoc'
40
+ rdoc.title = "configurable #{version}"
41
+ rdoc.rdoc_files.include('README*')
42
+ rdoc.rdoc_files.include('lib/**/*.rb')
43
+ end
data/TODO ADDED
@@ -0,0 +1 @@
1
+ * Add filters.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
data/examples/all.rb ADDED
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'processr'))
2
+
3
+ Processr.configure do |config|
4
+ config.root = File.expand_path(File.dirname(__FILE__))
5
+ config.out = File.join(config.root, 'output.txt')
6
+ end
7
+
8
+
9
+
10
+ # Simple text concatenation.
11
+
12
+ processor = Processr.new
13
+ processor << 'one.txt'
14
+ processor << 'two.txt'
15
+ processor.process!
16
+
17
+
18
+
19
+ # Simple textile filter.
20
+
21
+ TextileFilter = lambda do |buffer|
22
+
23
+ lookup = {
24
+ /_(.*)_/ => '<em>\1</em>',
25
+ /\*(.*)\*/ => '<strong>\1</strong>',
26
+ /\"(.*)\":(\S*)/ => '<a href="\2">\1</a>'
27
+ }
28
+
29
+ lookup.each_pair do |regex, replacement|
30
+ buffer.gsub!(regex, replacement)
31
+ end
32
+
33
+ buffer
34
+ end
35
+
36
+ processor = Processr.new
37
+ processor.add_filter(TextileFilter)
38
+ processor << 'text.textile'
39
+ processor.process!
40
+
41
+ puts "* Look in output.txt to see the result of this example."
data/examples/one.txt ADDED
@@ -0,0 +1 @@
1
+ one
@@ -0,0 +1 @@
1
+ A <em>simple</em> example of a <a href="http://www.textism.com/tools/textile/">textile</a> parser using a <strong>filter</strong>.
@@ -0,0 +1 @@
1
+ A _simple_ example of a "textile":http://www.textism.com/tools/textile/ parser using a *filter*.
data/examples/two.txt ADDED
@@ -0,0 +1 @@
1
+ two
data/lib/processr.rb ADDED
@@ -0,0 +1,47 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ class Processr
4
+ class << self
5
+ def root=(path); @root = path; end
6
+ def root; @root; end
7
+
8
+ def out=(path); @out = path; end
9
+ def out; @out; end
10
+
11
+ def configure(&block)
12
+ yield self
13
+ end
14
+ end
15
+
16
+ attr_accessor :buffer, :filters
17
+
18
+ def initialize
19
+ self.buffer = ""
20
+ self.filters = []
21
+ end
22
+
23
+ def add_filter(filter)
24
+ self.filters << filter
25
+ end
26
+
27
+ def process!
28
+ self.filters.each do |filter|
29
+ self.buffer = filter.call(self.buffer)
30
+ end
31
+
32
+ write_buffer!
33
+
34
+ true
35
+ end
36
+
37
+ def <<(file)
38
+ self.buffer << File.open(File.join(self.class.root, file)).read
39
+ end
40
+
41
+ private
42
+ def write_buffer!
43
+ output_file = File.open(self.class.out, "w+")
44
+ output_file.puts self.buffer
45
+ output_file.close
46
+ end
47
+ end
data/processr.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{processr}
8
+ s.version = "0.5.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Josh Nesbitt"]
12
+ s.date = %q{2010-07-13}
13
+ s.description = %q{Processr provides a really simple interface to processing a set of text files. Through the use of filters you can further modify output before writing the contents to a file.}
14
+ s.email = %q{josh@josh-nesbitt.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "TODO"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "Rakefile",
23
+ "TODO",
24
+ "VERSION",
25
+ "examples/all.rb",
26
+ "examples/one.txt",
27
+ "examples/output.txt",
28
+ "examples/text.textile",
29
+ "examples/two.txt",
30
+ "lib/processr.rb",
31
+ "processr.gemspec",
32
+ "readme.rdoc",
33
+ "spec/fixtures/one.js",
34
+ "spec/fixtures/two.js",
35
+ "spec/lib/processr_spec.rb",
36
+ "spec/spec_helper.rb",
37
+ "spec/watch.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/joshnesbitt/processr}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.6}
43
+ s.summary = %q{A simple text processing library}
44
+ s.test_files = [
45
+ "spec/lib/processr_spec.rb",
46
+ "spec/spec_helper.rb",
47
+ "spec/watch.rb",
48
+ "examples/all.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ end
63
+ end
64
+
data/readme.rdoc ADDED
@@ -0,0 +1,104 @@
1
+ = Processr
2
+
3
+ * Overview
4
+ * Installation
5
+ * Usage
6
+ * Bugs
7
+
8
+
9
+
10
+ == Overview
11
+
12
+ Processr is a simple text processing and concatenation library. It takes a number of input files and outputs a single file with the result. Text can be passed through filters to modify the output.
13
+
14
+ == Installation
15
+
16
+ The project is hosted on rubygems.org. Getting it is simple:
17
+
18
+ gem install processr
19
+
20
+ == Usage
21
+
22
+ === Configuration
23
+
24
+ Use the configuration block to setup Processr
25
+
26
+ Processr.configure do |config|
27
+ config.root = File.expand_path(File.dirname(__FILE__))
28
+ config.out = File.join(config.root, 'output.txt')
29
+ end
30
+
31
+ === Basic
32
+
33
+ processor = Processr.new
34
+ processor << 'input_one.txt'
35
+ processor << 'input_two.txt'
36
+ processor.process!
37
+
38
+ This will result in a single file being output with the contents of all files inputted.
39
+
40
+ === filters
41
+
42
+ Filters can be used to modify the output of a processing session. A filter is any object that responds to #call. Filters take a single argument (the input buffer) and must return the modified buffer for further processing. For example:
43
+
44
+ lambda do |buffer|
45
+ # ...do something with buffer here...
46
+ end
47
+
48
+ Or
49
+
50
+ class MyFilter
51
+
52
+ def self.call(buffer)
53
+ # ...do something with buffer here...
54
+ end
55
+
56
+ end
57
+
58
+ You can register a filter by calling #add_filter on an instance of Processr. A further example would be a really simple textile parser:
59
+
60
+ TextileFilter = lambda do |buffer|
61
+
62
+ lookup = {
63
+ /_(.*)_/ => '<em>\1</em>',
64
+ /\*(.*)\*/ => '<strong>\1</strong>',
65
+ /\"(.*)\":(\S*)/ => '<a href="\2">\1</a>'
66
+ }
67
+
68
+ lookup.each_pair do |regex, replacement|
69
+ buffer.gsub!(regex, replacement)
70
+ end
71
+
72
+ buffer
73
+ end
74
+
75
+ processor = Processr.new
76
+ processor.add_filter(TextileFilter)
77
+ processor << 'text.textile'
78
+ processor.process!
79
+
80
+ Run the examples for more information.
81
+
82
+
83
+
84
+ == Bugs
85
+
86
+ If you have any problems with processr, please file an issue at http://github.com/joshnesbitt/processr/issues.
87
+
88
+
89
+
90
+ == Note on Patches/Pull Requests
91
+
92
+ * Fork the project.
93
+ * Make your feature addition or bug fix.
94
+ * Add tests for it. This is important so I don't break it in a
95
+ future version unintentionally.
96
+ * Commit, do not mess with rakefile, version, or history.
97
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
98
+ * Send me a pull request. Bonus points for topic branches.
99
+
100
+
101
+
102
+ == Copyright
103
+
104
+ Copyright (c) 2010 Josh Nesbitt <josh@josh-nesbitt.net>. See LICENSE for details.
@@ -0,0 +1 @@
1
+ one
@@ -0,0 +1 @@
1
+ two
@@ -0,0 +1,34 @@
1
+ describe Processr do
2
+
3
+ before :all do
4
+ Processr.configure do |config|
5
+ config.root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
6
+ config.out = File.join(config.root, 'examples', 'all')
7
+ end
8
+ end
9
+
10
+ it "should successfully accept a configuration block" do
11
+ root = nil
12
+ out = nil
13
+
14
+ Processr.configure do |config|
15
+ config.root = root
16
+ config.out = out
17
+ end
18
+
19
+ Processr.root.should be_nil
20
+ Processr.out.should be_nil
21
+
22
+ root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
23
+ out = File.join(root, 'examples', 'all')
24
+
25
+ Processr.configure do |config|
26
+ config.root = root
27
+ config.out = out
28
+ end
29
+
30
+ Processr.root.should == root
31
+ Processr.out.should == out
32
+ end
33
+
34
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'processr'
4
+ require 'spec'
data/spec/watch.rb ADDED
@@ -0,0 +1,28 @@
1
+ # A simple alternative to autotest that isnt as painful
2
+
3
+ options = {
4
+ :options => "--require 'spec/spec_helper' --format nested --color",
5
+ :binary => "spec"
6
+ }
7
+
8
+ watch("(lib|spec)/(.*)\.rb") do |match|
9
+ puts %x[ clear ]
10
+
11
+ file = match[match.size - 1]
12
+ opts = options[:options]
13
+ binary = options[:binary]
14
+
15
+ files = []
16
+
17
+ ["spec/lib/*.rb", "spec/lib/*/*.rb"].each do |glob|
18
+ Dir.glob(glob).each { |f| files << f }
19
+ end
20
+
21
+ puts "Found:"
22
+ files.each { |f| puts "+ #{f}" }
23
+ puts ""
24
+ command = "#{binary} #{files.collect! { |f| File.expand_path(f) }.join(" ")} #{opts}"
25
+
26
+ system(command)
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: processr
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
+ platform: ruby
11
+ authors:
12
+ - Josh Nesbitt
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-13 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Processr provides a really simple interface to processing a set of text files. Through the use of filters you can further modify output before writing the contents to a file.
35
+ email: josh@josh-nesbitt.net
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - TODO
43
+ files:
44
+ - .gitignore
45
+ - LICENSE
46
+ - Rakefile
47
+ - TODO
48
+ - VERSION
49
+ - examples/all.rb
50
+ - examples/one.txt
51
+ - examples/output.txt
52
+ - examples/text.textile
53
+ - examples/two.txt
54
+ - lib/processr.rb
55
+ - processr.gemspec
56
+ - readme.rdoc
57
+ - spec/fixtures/one.js
58
+ - spec/fixtures/two.js
59
+ - spec/lib/processr_spec.rb
60
+ - spec/spec_helper.rb
61
+ - spec/watch.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/joshnesbitt/processr
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A simple text processing library
92
+ test_files:
93
+ - spec/lib/processr_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/watch.rb
96
+ - examples/all.rb