decorative_buildr 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.~
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ script: "rake test"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - jruby
8
+ gemfile:
9
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ decorative_buildr (0.1.5)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ minitest (2.11.4)
10
+ rake (0.9.2.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ decorative_buildr!
17
+ minitest (~> 2.11.4)
18
+ rake
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daniel Schmidt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # DecorativeBuildr
2
+
3
+ [![Build Status](https://secure.travis-ci.org/dsci/decorative_buildr.png)](http://travis-ci.org/dsci/decorative_buildr)
4
+
5
+ ## Buildr
6
+
7
+ A building module which could be included in any class to concat multiple strings with a seperator/line ending.
8
+
9
+ ```ruby
10
+ class Sample
11
+ include DecorativeBuildr::Builder
12
+ end
13
+
14
+ sample = Sample.new
15
+ sample.build_info(:line_ending => "<br/>") do |builder|
16
+ builder.add "One"
17
+ builder.add "Two"
18
+ end
19
+ ```
20
+
21
+ The result should be something like this:
22
+
23
+ ```html
24
+ One<br/>Two<br/>
25
+ ```
26
+
27
+ ## Is this useful?
28
+
29
+ Of course. For little things. ... Of course.
30
+
31
+ ### License
32
+ ---
33
+ See LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+ require "bundler/setup"
3
+
4
+ require 'rake/testtask'
5
+
6
+ require 'rake/testtask'
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs.push "lib"
10
+ t.test_files = FileList['test/*_spec.rb']
11
+ t.verbose = true
12
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'decorative_buildr'
3
+ s.version = '0.1.5'
4
+ s.platform = Gem::Platform::RUBY
5
+ s.author = 'Daniel Schmidt'
6
+ s.email = 'dsci@code79.net'
7
+ s.summary = 'DecorativeBuildr!'
8
+ s.description = 'Basic decorator pattern and a simple builder.'
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ s.require_paths = ["lib"]
13
+
14
+ # This will added later.
15
+ s.add_development_dependency('minitest','~> 2.11.4')
16
+ s.add_development_dependency('rake')
17
+ end
@@ -0,0 +1,12 @@
1
+ module DecorativeBuildr
2
+ class BaseDecorator
3
+
4
+ def initialize(decorated)
5
+ @decorated = decorated
6
+ end
7
+
8
+ def method_missing(method,*args)
9
+ @decorated.send(method,args)
10
+ end
11
+ end
12
+ end
data/lib/builder.rb ADDED
@@ -0,0 +1,59 @@
1
+ module DecorativeBuildr
2
+ # A building module which could be included in any
3
+ # class to concat multiple strings with a seperator/
4
+ # line ending.
5
+ #
6
+ # @example
7
+ # class Sample
8
+ # include Util::Builder
9
+ # end
10
+ #
11
+ # sample = Sample.new
12
+ # sample.build_info(:line_ending => "<br/>") do |builder|
13
+ # builder.add "One"
14
+ # builder.add "Two"
15
+ # end
16
+ #
17
+ #
18
+ # The result should be something like this:
19
+ #
20
+ # @example
21
+ # One<br/>Two<br/>
22
+ #
23
+ # @author Daniel Schmidt
24
+ module Builder
25
+
26
+ def add(line, options={})
27
+ @infos << rescue_nil_string(line,options) << @line_ending
28
+ end
29
+
30
+ # Concats multiple string with a line ending. It receives a block.
31
+ # @param [Hash] opt Optional configuration hash with :line_ending key, which is \n by default.
32
+ # @return [String] The concated String
33
+ def build_info(opt={},&block)
34
+ raise "Arguments in invalid form" unless opt.is_a?(Hash)
35
+ @infos = rescue_nil_string(@infos)
36
+ @line_ending = opt.fetch(:line_ending, "\n")
37
+ @pre = opt.fetch(:pre, "")
38
+ @after = opt.fetch(:after, "")
39
+ block.call(self)
40
+ @infos = "#{@pre}#{@line_ending}#{@infos}" unless @pre.empty?
41
+ @infos = "#{@infos}#{@line_endings}#{@after}" unless @after.empty?
42
+ return @infos
43
+ end
44
+
45
+ private
46
+
47
+ def rescue_nil_string(string, options=nil)
48
+ line = string.nil? ? "" : string
49
+ unless options.nil?
50
+ if options.has_key?(:tag)
51
+ tag = options[:tag]
52
+ line = string.nil? ? "<#{tag}></#{tag}" : "<#{tag}>#{string}</#{tag}>"
53
+ end
54
+ end
55
+ return line
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), '*.rb'))].each{|file| require file}
@@ -0,0 +1,87 @@
1
+ require 'minitest/autorun'
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'lib','decorative_buildr.rb'))
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ class TestBuildr
8
+ include DecorativeBuildr::Builder
9
+
10
+ def initialize
11
+ @lines = ["one", "two"]
12
+ end
13
+
14
+ def without_hooks(opt={})
15
+ if opt.has_key?(:line_ending)
16
+ build_info(:line_ending => opt[:line_ending]) do |builder|
17
+ @lines.each{|line| builder.add line}
18
+ end
19
+ else
20
+ build_info do |builder|
21
+ @lines.each{|line| builder.add line}
22
+ end
23
+ end
24
+ end
25
+
26
+ def info(hooks={})
27
+ procs = []
28
+ build_info(:pre => hooks[:pre], :after => hooks[:after]) do |builder|
29
+ if hooks.has_key?(:tag)
30
+ @lines.each{|line| builder.add line, :tag => hooks[:tag]}
31
+ else
32
+ @lines.each{|line| builder.add line}
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ describe "DecorativeBuildr" do
41
+
42
+ describe "with pre hooks" do
43
+
44
+ describe "and with tag hooks" do
45
+
46
+ subject{TestBuildr.new.info(:pre => "<ul>", :after => "</ul>", :tag => "li")}
47
+
48
+ ["<ul>","</ul>","<li>","</li>"].each do |tag|
49
+ it{subject.must_include tag}
50
+ end
51
+
52
+ end
53
+
54
+ describe "and without tag hooks" do
55
+
56
+ subject{TestBuildr.new.info(:pre => "<p>", :after=> "</p>")}
57
+
58
+ ["<p>","</p>"].each do |tag|
59
+ it{subject.must_include tag}
60
+ end
61
+
62
+ ["<ul>","</ul>","<li>","</li>"].each do |tag|
63
+ it{subject.wont_include tag}
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ describe "without pre hooks" do
71
+
72
+ subject{TestBuildr.new.without_hooks}
73
+
74
+ it{subject.must_include "one\n"}
75
+ it{subject.must_include "two\n"}
76
+
77
+ end
78
+
79
+ describe "with line_endings" do
80
+ subject{TestBuildr.new.without_hooks(:line_ending => "<br/>")}
81
+
82
+ it{subject.must_include "one<br/>"}
83
+ it{subject.must_include "two<br/>"}
84
+
85
+ end
86
+
87
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decorative_buildr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Schmidt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &70336625385440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.4
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70336625385440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70336625375140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70336625375140
36
+ description: Basic decorator pattern and a simple builder.
37
+ email: dsci@code79.net
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - .gitignore
43
+ - .travis.yml
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - decorative_buildr.gemspec
50
+ - lib/base_decorator.rb
51
+ - lib/builder.rb
52
+ - lib/decorative_buildr.rb
53
+ - test/decorative_buildr_spec.rb
54
+ homepage:
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.10
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: DecorativeBuildr!
78
+ test_files:
79
+ - test/decorative_buildr_spec.rb
80
+ has_rdoc: