rendering_engine 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmUyYzQxMDAzNDJhNmRhYjQ5YTllM2E1YTZjZmUwMzdjNTA3ZjBmOQ==
4
+ YzhkNmMzOWYzMmU3MmFhMDI5NjA0N2FmMGVhMTA5ZWQ4MjVmMGNmYQ==
5
5
  data.tar.gz: !binary |-
6
- ZDBjZTcxM2UyNWFiYjI4OWQ2YzhlNTM1YzE3NmZlYTkzNzM0MmVmOQ==
6
+ NTRkZDIxYTA5MWU1MTA5NDk4NGQwMThmNmM1NDU3N2VhNTE4NDVlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjcwYTc1ZTY5YjBlNDdkYWQ3YTViNzhmYjM4ZDQ5MDk2MDM2MWUwYTBlZjIx
10
- NzY1NTYyOGE1YzE0YzRmMTM0YTkzYTc4ZDdkYWRkOWU3OTZiYTdlZjZjNzE3
11
- ODlhNzJmMjZjM2ZjNjNiNjUzYWJiNmI3MzMzYTAwZWRhYmQxY2Q=
9
+ OWNkNzRhNmNhOGNmYzczMTcxMzIwN2Q5YzY2MTQ1NWRlNmYzYjQ5ZTM3NTEw
10
+ NDMyYmI5N2U1MTNjMTA0ZGVkZTdlOGU5OTNmMGQzZmRkODUxZTRkYzQ4NTdl
11
+ NjYwNDQ5OGQ2N2QwMjBkYjk5MDc4ZjA3MDUwNWM4ZTY1YmJmNmI=
12
12
  data.tar.gz: !binary |-
13
- YjUxNjA4YjY4OTgzODhhODBlZjdmY2U3MTM3ZDk0NmE0NDQ1YWZlNDc5Mjgz
14
- MDVkNDM1ZDBjYmE4ZDFjYjlkNjEwOTlmNDZlYjYxZTFjNTMyMzAxM2FhYTZk
15
- NTEwNmRkYTU1MWUxMWFkZWZmMjMzYTM5NWY3ZTJlMDIxZWE4YzI=
13
+ ZTlkNDM0ZmYxNzYwYzkyMGE0YzdkMmJlMWQyM2M2Njk1MzJlZDc3NGVjY2Nh
14
+ ZjljNjI2MzI1NjNhYTM5YmJjOGNhYjAwMjM2ZWI5ZDQyZTAyOGJiYTg2Zjg3
15
+ NzkwODdmMDY1NTI4MTgyZDFjNWI1YmFjNmZjMDI5M2FhODhjZDg=
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # RenderingEngine
2
2
 
3
- TODO: Write a gem description
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
@@ -18,7 +16,77 @@ Or install it yourself as:
18
16
 
19
17
  ## Usage
20
18
 
21
- TODO: Write usage instructions here
19
+ $ content_provider = RenderingEngine::Provider.new(base_path)
20
+ $ content = content_provider.get(relative_file_path)
21
+ $ content.source #gets source of file (rendered or not :D)
22
+ $ content.kind return (:orginal, :template, :unknown)
23
+
24
+ In controller can looks like this:
25
+
26
+ ---
27
+ def show
28
+ path = "#{params[:client]}/#{params[:path]}"
29
+ data = params[:data]
30
+
31
+ content = content_provider.get(path, data)
32
+ return not_found if content.unknown?
33
+
34
+ render text: content.source
35
+ end
36
+
37
+ def content_provider
38
+ @content_provider ||= RenderingEngine::Provider.new(Rails.root.join('app/content'))
39
+ end
40
+ ---
41
+
42
+ ## Own Helper class
43
+
44
+ ```
45
+
46
+ class ContentCustomHelpers
47
+ def initialize(opts={})
48
+ @base_path = opts.fetch(:base_path)
49
+ @data = opts[:data]
50
+ end
51
+
52
+ def make_some_stuff
53
+ "best line ever!"
54
+ end
55
+
56
+ def render(file_relative_path)
57
+ file_path = File.join(base_path, file_relative_path)
58
+
59
+ RenderingEngine::Content.new(file_path, data: data, custom_helper: self.class).source
60
+ end
61
+
62
+ attr_reader :data
63
+
64
+ private
65
+
66
+ attr_reader :base_path
67
+ end
68
+
69
+
70
+ ```
71
+
72
+ ### Usage own custom class
73
+
74
+ ```
75
+
76
+ provider = RenderingEngine::Provider.new(Rails.root.join('app/content'), custom_helper: ContentCustomHelpers)
77
+ provider.get(path).source
78
+
79
+ ```
80
+
81
+ or
82
+
83
+ ```
84
+
85
+ provider = RenderingEngine::Provider.new(Rails.root.join('app/content'))
86
+ provider.get(path, custom_helper: ContentCustomHelpers).source
87
+
88
+
89
+ ```
22
90
 
23
91
  ## Contributing
24
92
 
@@ -2,18 +2,23 @@ require 'erb'
2
2
 
3
3
  module RenderingEngine
4
4
  class Content
5
- attr_reader :file_path
5
+ attr_reader :file_path, :data
6
6
 
7
- def initialize(file_path, base_folder_path=nil)
7
+ def initialize(file_path, opts={})
8
8
  @file_path = file_path
9
- @base_folder_path = base_folder_path
9
+ @base_folder_path = opts[:base_folder_path]
10
+ @data = opts[:data]
11
+ @custom_helper = opts[:custom_helper]
10
12
  end
11
13
 
12
14
  def source
13
15
  @source ||= (
14
16
  case kind
15
17
  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 })
18
+ when :template
19
+ ERB.new(File.read(file_path_as_erb)).result(
20
+ helper(base_folder_path, data).instance_eval { binding }
21
+ )
17
22
  else ''
18
23
  end
19
24
  )
@@ -49,8 +54,10 @@ module RenderingEngine
49
54
 
50
55
  private
51
56
 
52
- def helpers(path)
53
- ContentHelpers.new(base_path: path)
57
+ attr_reader :custom_helper
58
+
59
+ def helper(path, content_data)
60
+ (custom_helper || ContentHelpers).new(base_path: path, data: content_data)
54
61
  end
55
62
 
56
63
  def orginal_file_present?
@@ -2,14 +2,17 @@ module RenderingEngine
2
2
  class ContentHelpers
3
3
  def initialize(opts={})
4
4
  @base_path = opts.fetch(:base_path)
5
+ @data = opts[:data]
5
6
  end
6
7
 
7
8
  def render(file_relative_path)
8
9
  file_path = File.join(base_path, file_relative_path)
9
10
 
10
- RenderingEngine::Content.new(file_path).source
11
+ RenderingEngine::Content.new(file_path, data: data).source
11
12
  end
12
13
 
14
+ attr_reader :data
15
+
13
16
  private
14
17
 
15
18
  attr_reader :base_path
@@ -1,16 +1,18 @@
1
1
  module RenderingEngine
2
2
  class Provider
3
- def initialize(base_path)
3
+ def initialize(base_path, base_opts={})
4
4
  @base_path = base_path
5
+ @base_opts = base_opts
5
6
  end
6
7
 
7
- def get(relative_path)
8
- file_path = File.join(base_path, relative_path)
9
- Content.new(file_path)
8
+ def get(relative_path, opts={})
9
+ file_path = File.join(base_path, relative_path)
10
+ content_opts = base_opts.merge(opts)
11
+ Content.new(file_path, content_opts)
10
12
  end
11
13
 
12
14
  private
13
15
 
14
- attr_reader :base_path
16
+ attr_reader :base_path, :base_opts
15
17
  end
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module RenderingEngine
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["pniemczyk@o2.pl"]
11
11
  spec.description = %q{ Rendering engine based on ERB }
12
12
  spec.summary = %q{ Rendering engine based on ERB }
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/pniemczyk/rendering_engine"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -6,11 +6,12 @@ describe RenderingEngine::ContentHelpers do
6
6
  let(:file_path) { File.join(base_path, file_relative_path) }
7
7
  let(:content) { double('content_object', source: source) }
8
8
  let(:source) { 'file_source' }
9
- subject { described_class.new(base_path: base_path) }
9
+ let(:content_data) {{ name: 'pawel' }}
10
+ subject { described_class.new(base_path: base_path, data: content_data) }
10
11
 
11
12
  it '#render' do
12
13
  RenderingEngine::Content.should_receive(:new)
13
- .with(file_path)
14
+ .with(file_path, data: content_data)
14
15
  .and_return(content)
15
16
 
16
17
  subject.render(file_relative_path).should eq source
@@ -6,9 +6,17 @@ describe RenderingEngine::Content do
6
6
  let(:relative_path) { 'login/form.html' }
7
7
  let(:file_path) { File.join(base_path, relative_path) }
8
8
  let(:content) { double('ContentObject') }
9
+ let(:content_data) { nil }
10
+ let(:custom_helper) { nil }
11
+ let(:opts) do
12
+ {
13
+ base_folder_path: test_base_path,
14
+ data: content_data,
15
+ custom_helper: custom_helper
16
+ }
17
+ end
9
18
 
10
-
11
- subject { described_class.new(file_path, test_base_path) }
19
+ subject { described_class.new(file_path, opts) }
12
20
 
13
21
  context '#source' do
14
22
 
@@ -48,7 +56,7 @@ describe RenderingEngine::Content do
48
56
  let(:base_folder_path) { 'root/contract/files/login' }
49
57
  before do
50
58
  ERB.should_receive(:new).with(source).and_return(erb_instance)
51
- subject.should_receive(:helpers).with(base_folder_path)
59
+ subject.should_receive(:helper).with(base_folder_path, content_data)
52
60
  .and_return(double)
53
61
  erb_instance.should_receive(:result).with(an_instance_of(Binding))
54
62
  .and_return(rendered_source)
@@ -5,12 +5,15 @@ describe RenderingEngine::Provider do
5
5
  let(:relative_path) { 'login/form.html' }
6
6
  let(:file_path) { File.join(base_path, relative_path) }
7
7
  let(:content) { double('ContentObject') }
8
+ let(:data) { double('data') }
9
+ let(:custom_helper) { double('custom_helper') }
10
+ let(:opts) {{ data: data, custom_helper: custom_helper }}
8
11
  subject { described_class.new(base_path) }
9
12
 
10
13
  it '#get' do
11
14
  RenderingEngine::Content.should_receive(:new)
12
- .with(file_path)
15
+ .with(file_path, opts)
13
16
  .and_return(content)
14
- subject.get(relative_path).should be content
17
+ subject.get(relative_path, opts).should be content
15
18
  end
16
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rendering_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Niemczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ files:
75
75
  - spec/rendering_engine/content_spec.rb
76
76
  - spec/rendering_engine/provider_spec.rb
77
77
  - spec/spec_helper.rb
78
- homepage: ''
78
+ homepage: https://github.com/pniemczyk/rendering_engine
79
79
  licenses:
80
80
  - MIT
81
81
  metadata: {}