lb-project 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba077de0e17958d3f6b91b77d21fe49f389288c9a8f0da853ede9be83b190874
4
- data.tar.gz: 7c6dbb470c3d4bb2837d7e4dfa5e05b339d9eb3ec9d095af37be028ef3565159
3
+ metadata.gz: '06996fcfa5635e9e17d9a7e9468caaba7202076f3830b5f7b8b410e2b383fc3f'
4
+ data.tar.gz: 6fb9a7e95fa4add0ee698c483b3411b805fda49be01884f5f12374b7b0f0a9ce
5
5
  SHA512:
6
- metadata.gz: '08131a9358ba63d99523eab4fe909908d8fa473518e7aa4542aa5d423fac9bd156cbb43771dfa35b2bd4f8fd09c7566a30d2a88d415087c1ee633bd544c58f28'
7
- data.tar.gz: 268c9285eb65abf2ddf44ea05eaf14e5e341698784aa5e3b495c075922110e830ec98d5fac99278cb32b55f4c63712801f26529c8c272d15945658e937e78934
6
+ metadata.gz: 469efbc9289a0daf4da1faf2f599a9e834b270586b7563709d7d0bad085f8ea38575c2434e38d5ee0c53d1ec58c9542a3b79dc884f9eb5c2c9ae56c7df685696
7
+ data.tar.gz: b061f346767b0eafd36ded6583aee10e446744ec549f317fc9d1ade3ad1af070b611d063c905b1ef95a2b0ece774bb98b70fb6c805e0067aca54b6fd80c45a49
@@ -8,8 +8,20 @@ class Roda
8
8
  # Plugin instance methods
9
9
  module InstanceMethods
10
10
  def page(name, overrides = {})
11
- page = LB::Project::Page.page_registry[name].new
12
- page.call(current_context(page.with(overrides)))
11
+ view_for(LB::Project::Page.page_registry, name, overrides)
12
+ end
13
+
14
+ def view(name, overrides = {})
15
+ view_for(LB::Project::View.view_registry, name, overrides)
16
+ end
17
+
18
+ def view_for(registry, name, overrides)
19
+ registry[name].new.with(overrides.merge(site: current_site)).render
20
+ end
21
+
22
+ def flush_flash
23
+ flash.keep
24
+ flash.sweep
13
25
  end
14
26
 
15
27
  private
@@ -18,13 +30,6 @@ class Roda
18
30
  site.with_flash(flash)
19
31
  end
20
32
 
21
- def current_context(page)
22
- {
23
- context: ::Struct.new(:site, :page).new(current_site, page),
24
- locals: {}
25
- }
26
- end
27
-
28
33
  def site
29
34
  LB::Project.settings.site.new.with(csrf_config.merge(session_config))
30
35
  end
@@ -3,6 +3,6 @@
3
3
  module LB
4
4
  module Project
5
5
  # Version
6
- VERSION = '0.2.3'
6
+ VERSION = '0.3.0'
7
7
  end
8
8
  end
@@ -11,9 +11,34 @@ module LB
11
11
  view.setting :layout, layout
12
12
  end
13
13
 
14
- def with(_options)
14
+ attr_reader :site
15
+
16
+ def with(options)
17
+ @site = options.fetch(:site, LB::Project.settings.site.new)
15
18
  self
16
19
  end
20
+
21
+ def view(name, overrides = {})
22
+ LB::Project::View.view_registry[name]
23
+ .new
24
+ .with(overrides.merge(site: site))
25
+ .render
26
+ end
27
+
28
+ def render(locals = {})
29
+ render_with(site, self, locals)
30
+ end
31
+
32
+ def render_with(site, page, locals = {})
33
+ call(with_context(site, page, locals))
34
+ end
35
+
36
+ def with_context(site, page, locals = {})
37
+ {
38
+ context: ::Struct.new(:site, :page).new(site, page),
39
+ locals: locals
40
+ }
41
+ end
17
42
  end
18
43
  end
19
44
  end
@@ -12,7 +12,8 @@ shared_context 'setup' do
12
12
  let(:settings) do
13
13
  LB::Project::Settings.new(
14
14
  root: root,
15
- config: config
15
+ config: config,
16
+ site: LB::Project::Site
16
17
  )
17
18
  end
18
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lb-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firas Zaidan