kerb 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3fa5392ab24d8669f5d493f867ac403931e0f4fe
4
+ data.tar.gz: 084a52d50da75ff0cfc5b01bedf5551b206ff15f
5
+ SHA512:
6
+ metadata.gz: 2022cd63918d174c9e57fcbf462f5a02d973214b8ac657a8dbef3b5ffd0894349968e834616111343717e9cb1e3810807d44810736f39e9ecc48fc37093f7ad2
7
+ data.tar.gz: eaa039f8890b347efeca5127d56245f59fb9a25303fab325c4d0c9a27fd95564c41395a7922e2b01f11b891cf79c8de81bccc99211d7ddf43c507e45ca301a8f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.scrutinizer.yml ADDED
@@ -0,0 +1,4 @@
1
+ checks:
2
+ ruby:
3
+ code_rating: true
4
+ duplicate_code: true
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.4
5
+ - 2.1.8
6
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at sebastiaan@hoppinger.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kerb.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sebastiaan de Geus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Kerb
2
+
3
+ [![Build Status](https://travis-ci.org/sebastiaandegeus/kerb.svg?branch=master)](https://travis-ci.org/sebastiaandegeus/kerb)
4
+ [![Code Climate](https://codeclimate.com/github/sebastiaandegeus/kerb/badges/gpa.svg)](https://codeclimate.com/github/sebastiaandegeus/kerb)
5
+ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sebastiaandegeus/kerb/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sebastiaandegeus/kerb/?branch=master)
6
+
7
+ __ERB__ rendering can be a little annoying at times. So this library aims to solve this problem by offering an easy interface to render ERB from a string, from a file or towards a file.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'kerb'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```
26
+ $ gem install kerb
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Render a string
32
+
33
+ ```ruby
34
+ erb = 'my <%= @foo %> <%= @bar %>'
35
+ vars = {
36
+ foo: 'lovely',
37
+ bar: 'garden'
38
+ }
39
+
40
+ Kerb.render(erb, vars) #=> "my lovely garden"
41
+ ```
42
+
43
+ ### Render to a file
44
+
45
+ ```ruby
46
+ erb = 'my <%= @foo %> <%= @bar %>'
47
+ vars = {
48
+ foo: 'lovely',
49
+ bar: 'garden'
50
+ }
51
+ file = 'path_to_file'
52
+
53
+ Kerb.render_to_file(erb, vars, file)
54
+
55
+ File.read(file) #=> "my lovely garden"
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sebastiaandegeus/kerb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
61
+
62
+ ## License
63
+
64
+ Copyright (c) 2016 Sebastiaan de Geus
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://github.com/sebastiaandegeus/kerb/blob/master/LICENSE).
67
+
68
+
69
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kerb'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ def reload!
14
+ files = $LOADED_FEATURES.select { |feat| feat =~ %r{\/kerb\/} }
15
+ files.each { |file| load file }
16
+ end
17
+
18
+ require 'irb'
19
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kerb.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kerb/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'kerb'
8
+ s.version = Kerb.version
9
+ s.author = 'Sebastiaan de Geus'
10
+ s.email = ['sebastiaan@hoppinger.com']
11
+
12
+ s.summary = 'Easily render ERB'
13
+ s.description = 'Kerb renders ERB strings, templates and files'
14
+ s.homepage = 'https://github.com/sebastiaandegeus/kerb'
15
+ s.license = 'MIT'
16
+
17
+ s.require_paths = ['lib']
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+
21
+ s.add_development_dependency 'bundler'
22
+ s.add_development_dependency 'rake', '~> 10.5'
23
+ s.add_development_dependency 'rspec', '~> 3.4'
24
+ s.add_development_dependency 'fakefs', '~> 0.8'
25
+ end
data/lib/kerb.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'erb'
2
+ require 'kerb/template'
3
+ require 'kerb/version'
4
+
5
+ module Kerb
6
+ def self.render(erb, vars)
7
+ template = Kerb::Template.new(erb, vars)
8
+ template.render
9
+ end
10
+
11
+ def self.render_to_file(erb, vars, file)
12
+ template = Kerb::Template.new(erb, vars)
13
+ output = template.render
14
+
15
+ File.open(file, 'w') { |f| f.write(output) }
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Kerb
2
+ class Template
3
+ def initialize(erb, vars)
4
+ @erb = erb
5
+ vars.each { |k, v| instance_variable_set("@#{k}", v) }
6
+ end
7
+
8
+ def render
9
+ ERB.new(@erb).result(binding)
10
+ end
11
+
12
+ def render_to_file(file)
13
+ File.open(file, 'w') { |f| f.write(render) }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Kerb
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
+ end
9
+
10
+ def self.version
11
+ Gem::Version.new VERSION::STRING
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ my lovely garden
2
+ is beatiful
@@ -0,0 +1,2 @@
1
+ my <%= @foo %> <%= @bar %>
2
+ is <%= @baz %>
data/spec/kerb_spec.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kerb do
4
+ it 'renders a single line template' do
5
+ erb = 'my <%= @foo %> <%= @bar %>'
6
+ vars = {
7
+ foo: 'lovely',
8
+ bar: 'garden'
9
+ }
10
+
11
+ result = Kerb.render(erb, vars)
12
+
13
+ expect(result).to eq('my lovely garden')
14
+ end
15
+
16
+ it 'renders multiple lines template' do
17
+ erb = "my <%= @foo %> <%= @bar %>\n is <%= @baz %>"
18
+ vars = {
19
+ foo: 'lovely',
20
+ bar: 'garden',
21
+ baz: 'beatiful'
22
+ }
23
+
24
+ result = Kerb.render(erb, vars)
25
+
26
+ expect(result).to eq("my lovely garden\n is beatiful")
27
+ end
28
+
29
+ it 'renders from a template file' do
30
+ erb = Helper.data('multiline.erb')
31
+ output = Helper.data('multiline')
32
+
33
+ vars = {
34
+ foo: 'lovely',
35
+ bar: 'garden',
36
+ baz: 'beatiful'
37
+ }
38
+
39
+ result = Kerb.render(erb, vars)
40
+
41
+ expect(result).to eq(output)
42
+ end
43
+
44
+ it 'renders to a file', fakefs: true do
45
+ erb = 'my <%= @foo %> <%= @bar %>'
46
+ vars = {
47
+ foo: 'lovely',
48
+ bar: 'garden'
49
+ }
50
+
51
+ Kerb.render_to_file(erb, vars, 'file')
52
+
53
+ expect(File.read('file')).to eq('my lovely garden')
54
+ end
55
+
56
+ it 'has a version number' do
57
+ expect(Kerb::VERSION).not_to be nil
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'kerb'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ RSpec.configure do |config|
6
+ config.include FakeFS::SpecHelpers, fakefs: true
7
+ end
8
+
9
+ module Helper
10
+ def self.data(file)
11
+ data = File.expand_path('../../spec/data', __FILE__)
12
+ path = File.join(data, file)
13
+ File.read(path)
14
+ end
15
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kerb::Template do
4
+ it 'renders a single line template' do
5
+ erb = 'my <%= @foo %> <%= @bar %>'
6
+ vars = {
7
+ foo: 'lovely',
8
+ bar: 'garden'
9
+ }
10
+
11
+ template = Kerb::Template.new(erb, vars)
12
+ result = template.render
13
+
14
+ expect(result).to eq('my lovely garden')
15
+ end
16
+
17
+ it 'renders multiple lines template' do
18
+ erb = "my <%= @foo %> <%= @bar %>\n is <%= @baz %>"
19
+ vars = {
20
+ foo: 'lovely',
21
+ bar: 'garden',
22
+ baz: 'beatiful'
23
+ }
24
+
25
+ template = Kerb::Template.new(erb, vars)
26
+ result = template.render
27
+
28
+ expect(result).to eq("my lovely garden\n is beatiful")
29
+ end
30
+
31
+ it 'renders from a template file' do
32
+ erb = Helper.data('multiline.erb')
33
+ output = Helper.data('multiline')
34
+
35
+ vars = {
36
+ foo: 'lovely',
37
+ bar: 'garden',
38
+ baz: 'beatiful'
39
+ }
40
+
41
+ template = Kerb::Template.new(erb, vars)
42
+ result = template.render
43
+
44
+ expect(result).to eq(output)
45
+ end
46
+
47
+ it 'renders to a file', fakefs: true do
48
+ erb = 'my <%= @foo %> <%= @bar %>'
49
+ vars = {
50
+ foo: 'lovely',
51
+ bar: 'garden'
52
+ }
53
+
54
+ template = Kerb::Template.new(erb, vars)
55
+ template.render_to_file('garden')
56
+
57
+ expect(File.read('garden')).to eq('my lovely garden')
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kerb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastiaan de Geus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ description: Kerb renders ERB strings, templates and files
70
+ email:
71
+ - sebastiaan@hoppinger.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".ruby-version"
80
+ - ".scrutinizer.yml"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - kerb.gemspec
90
+ - lib/kerb.rb
91
+ - lib/kerb/template.rb
92
+ - lib/kerb/version.rb
93
+ - spec/data/multiline
94
+ - spec/data/multiline.erb
95
+ - spec/kerb_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/template_spec.rb
98
+ homepage: https://github.com/sebastiaandegeus/kerb
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Easily render ERB
122
+ test_files:
123
+ - spec/data/multiline
124
+ - spec/data/multiline.erb
125
+ - spec/kerb_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/template_spec.rb