rendering_engine 0.0.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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rendering_engine.rb +8 -0
- data/lib/rendering_engine/content.rb +68 -0
- data/lib/rendering_engine/content_helpers.rb +17 -0
- data/lib/rendering_engine/provider.rb +16 -0
- data/lib/rendering_engine/version.rb +3 -0
- data/rendering_engine.gemspec +24 -0
- data/spec/rendering_engine/content_helpers_spec.rb +18 -0
- data/spec/rendering_engine/content_spec.rb +114 -0
- data/spec/rendering_engine/provider_spec.rb +16 -0
- data/spec/spec_helper.rb +22 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmUyYzQxMDAzNDJhNmRhYjQ5YTllM2E1YTZjZmUwMzdjNTA3ZjBmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDBjZTcxM2UyNWFiYjI4OWQ2YzhlNTM1YzE3NmZlYTkzNzM0MmVmOQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjcwYTc1ZTY5YjBlNDdkYWQ3YTViNzhmYjM4ZDQ5MDk2MDM2MWUwYTBlZjIx
|
10
|
+
NzY1NTYyOGE1YzE0YzRmMTM0YTkzYTc4ZDdkYWRkOWU3OTZiYTdlZjZjNzE3
|
11
|
+
ODlhNzJmMjZjM2ZjNjNiNjUzYWJiNmI3MzMzYTAwZWRhYmQxY2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjUxNjA4YjY4OTgzODhhODBlZjdmY2U3MTM3ZDk0NmE0NDQ1YWZlNDc5Mjgz
|
14
|
+
MDVkNDM1ZDBjYmE4ZDFjYjlkNjEwOTlmNDZlYjYxZTFjNTMyMzAxM2FhYTZk
|
15
|
+
NTEwNmRkYTU1MWUxMWFkZWZmMjMzYTM5NWY3ZTJlMDIxZWE4YzI=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Paweł Niemczyk
|
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,29 @@
|
|
1
|
+
# RenderingEngine
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rendering_engine'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rendering_engine
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module RenderingEngine
|
4
|
+
class Content
|
5
|
+
attr_reader :file_path
|
6
|
+
|
7
|
+
def initialize(file_path, base_folder_path=nil)
|
8
|
+
@file_path = file_path
|
9
|
+
@base_folder_path = base_folder_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def source
|
13
|
+
@source ||= (
|
14
|
+
case kind
|
15
|
+
when :orginal then File.read(file_path)
|
16
|
+
when :template then ERB.new(File.read(file_path_as_erb)).result(helpers(base_folder_path).instance_eval { binding })
|
17
|
+
else ''
|
18
|
+
end
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def kind
|
23
|
+
@kind ||= (
|
24
|
+
if orginal_file_present?
|
25
|
+
:orginal
|
26
|
+
elsif file_as_erb_present?
|
27
|
+
:template
|
28
|
+
else
|
29
|
+
:unknown
|
30
|
+
end
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def template?
|
35
|
+
kind == :template
|
36
|
+
end
|
37
|
+
|
38
|
+
def orginal?
|
39
|
+
kind == :orginal
|
40
|
+
end
|
41
|
+
|
42
|
+
def unknown?
|
43
|
+
kind == :unknown
|
44
|
+
end
|
45
|
+
|
46
|
+
def base_folder_path
|
47
|
+
@base_folder_path ||= File.dirname(file_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def helpers(path)
|
53
|
+
ContentHelpers.new(base_path: path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def orginal_file_present?
|
57
|
+
File.exist?(file_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def file_as_erb_present?
|
61
|
+
File.exist?(file_path_as_erb)
|
62
|
+
end
|
63
|
+
|
64
|
+
def file_path_as_erb
|
65
|
+
@file_as_erb ||= "#{file_path}.erb"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RenderingEngine
|
2
|
+
class ContentHelpers
|
3
|
+
def initialize(opts={})
|
4
|
+
@base_path = opts.fetch(:base_path)
|
5
|
+
end
|
6
|
+
|
7
|
+
def render(file_relative_path)
|
8
|
+
file_path = File.join(base_path, file_relative_path)
|
9
|
+
|
10
|
+
RenderingEngine::Content.new(file_path).source
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :base_path
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RenderingEngine
|
2
|
+
class Provider
|
3
|
+
def initialize(base_path)
|
4
|
+
@base_path = base_path
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(relative_path)
|
8
|
+
file_path = File.join(base_path, relative_path)
|
9
|
+
Content.new(file_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :base_path
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rendering_engine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rendering_engine"
|
8
|
+
spec.version = RenderingEngine::VERSION
|
9
|
+
spec.authors = ["Paweł Niemczyk"]
|
10
|
+
spec.email = ["pniemczyk@o2.pl"]
|
11
|
+
spec.description = %q{ Rendering engine based on ERB }
|
12
|
+
spec.summary = %q{ Rendering engine based on ERB }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RenderingEngine::ContentHelpers do
|
4
|
+
let(:base_path) { 'root/path' }
|
5
|
+
let(:file_relative_path) { 'login.haml' }
|
6
|
+
let(:file_path) { File.join(base_path, file_relative_path) }
|
7
|
+
let(:content) { double('content_object', source: source) }
|
8
|
+
let(:source) { 'file_source' }
|
9
|
+
subject { described_class.new(base_path: base_path) }
|
10
|
+
|
11
|
+
it '#render' do
|
12
|
+
RenderingEngine::Content.should_receive(:new)
|
13
|
+
.with(file_path)
|
14
|
+
.and_return(content)
|
15
|
+
|
16
|
+
subject.render(file_relative_path).should eq source
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RenderingEngine::Content do
|
4
|
+
let(:test_base_path){ nil }
|
5
|
+
let(:base_path) { 'root/contract/files' }
|
6
|
+
let(:relative_path) { 'login/form.html' }
|
7
|
+
let(:file_path) { File.join(base_path, relative_path) }
|
8
|
+
let(:content) { double('ContentObject') }
|
9
|
+
|
10
|
+
|
11
|
+
subject { described_class.new(file_path, test_base_path) }
|
12
|
+
|
13
|
+
context '#source' do
|
14
|
+
|
15
|
+
before(:each) { subject.should_receive(:kind).and_return(kind) }
|
16
|
+
|
17
|
+
context 'when file is not found' do
|
18
|
+
let(:kind) { :unknown }
|
19
|
+
|
20
|
+
it 'returns empty string' do
|
21
|
+
subject.source.should eq ''
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when orginal file is found' do
|
26
|
+
let(:kind) { :orginal }
|
27
|
+
let(:source) { 'file_source' }
|
28
|
+
before { File.should_receive(:read).with(file_path).and_return(source) }
|
29
|
+
|
30
|
+
it 'returns source of file' do
|
31
|
+
subject.source.should eq source
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when orginal file is not found but template file is found' do
|
36
|
+
let(:kind) { :template }
|
37
|
+
let(:source) { 'calc 1+1=<%= 1+1 %>' }
|
38
|
+
let(:rendered_source) { 'calc 1+1=2' }
|
39
|
+
let(:erb_file_path) { "#{file_path}.erb" }
|
40
|
+
before { File.should_receive(:read).with(erb_file_path).and_return(source) }
|
41
|
+
|
42
|
+
it 'returns rendered source' do
|
43
|
+
subject.source.should eq rendered_source
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'erb result' do
|
47
|
+
let(:erb_instance) { double('erb_instance') }
|
48
|
+
let(:base_folder_path) { 'root/contract/files/login' }
|
49
|
+
before do
|
50
|
+
ERB.should_receive(:new).with(source).and_return(erb_instance)
|
51
|
+
subject.should_receive(:helpers).with(base_folder_path)
|
52
|
+
.and_return(double)
|
53
|
+
erb_instance.should_receive(:result).with(an_instance_of(Binding))
|
54
|
+
.and_return(rendered_source)
|
55
|
+
end
|
56
|
+
it 'receives helper' do
|
57
|
+
subject.source.should eq rendered_source
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context '#kind' do
|
64
|
+
context 'when orginal_file_present' do
|
65
|
+
before { subject.should_receive(:orginal_file_present?).and_return(true) }
|
66
|
+
it 'returns :orginal' do
|
67
|
+
subject.kind.should eq :orginal
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when orginal_file_present is missing but template file is present' do
|
72
|
+
|
73
|
+
before do
|
74
|
+
subject.should_receive(:orginal_file_present?).and_return(false)
|
75
|
+
subject.should_receive(:file_as_erb_present?).and_return(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns :template' do
|
79
|
+
subject.kind.should eq :template
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when orginal and template file is missing' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
subject.should_receive(:orginal_file_present?).and_return(false)
|
87
|
+
subject.should_receive(:file_as_erb_present?).and_return(false)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns :unknown' do
|
91
|
+
subject.kind.should eq :unknown
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
%w{template orginal unknown}.each do |method_name|
|
97
|
+
it "##{method_name}? returns true when content kind is :#{method_name}" do
|
98
|
+
subject.should_receive(:kind).and_return(method_name.to_sym)
|
99
|
+
subject.public_send("#{method_name}?").should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "##{method_name}? returns false when content kind is not :#{method_name}" do
|
103
|
+
subject.should_receive(:kind).and_return(:bad)
|
104
|
+
subject.public_send("#{method_name}?").should be_false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it '#base_folder_path' do
|
109
|
+
subject.should_receive(:file_path).and_return(relative_path)
|
110
|
+
subject.base_folder_path.should eq 'login'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RenderingEngine::Provider do
|
4
|
+
let(:base_path) { 'root/contract/files' }
|
5
|
+
let(:relative_path) { 'login/form.html' }
|
6
|
+
let(:file_path) { File.join(base_path, relative_path) }
|
7
|
+
let(:content) { double('ContentObject') }
|
8
|
+
subject { described_class.new(base_path) }
|
9
|
+
|
10
|
+
it '#get' do
|
11
|
+
RenderingEngine::Content.should_receive(:new)
|
12
|
+
.with(file_path)
|
13
|
+
.and_return(content)
|
14
|
+
subject.get(relative_path).should be content
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/rendering_engine')
|
9
|
+
require 'rspec'
|
10
|
+
require 'ostruct'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rendering_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Niemczyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-22 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: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ! ' Rendering engine based on ERB '
|
56
|
+
email:
|
57
|
+
- pniemczyk@o2.pl
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/rendering_engine.rb
|
69
|
+
- lib/rendering_engine/content.rb
|
70
|
+
- lib/rendering_engine/content_helpers.rb
|
71
|
+
- lib/rendering_engine/provider.rb
|
72
|
+
- lib/rendering_engine/version.rb
|
73
|
+
- rendering_engine.gemspec
|
74
|
+
- spec/rendering_engine/content_helpers_spec.rb
|
75
|
+
- spec/rendering_engine/content_spec.rb
|
76
|
+
- spec/rendering_engine/provider_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: ''
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.1.10
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Rendering engine based on ERB
|
102
|
+
test_files:
|
103
|
+
- spec/rendering_engine/content_helpers_spec.rb
|
104
|
+
- spec/rendering_engine/content_spec.rb
|
105
|
+
- spec/rendering_engine/provider_spec.rb
|
106
|
+
- spec/spec_helper.rb
|