hanami-view 0.0.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ module Hanami
2
+ module View
3
+ module Rendering
4
+ # Find a view
5
+ #
6
+ # @api private
7
+ # @since 0.1.0
8
+ #
9
+ # @see Hanami::View::Rendering::Registry
10
+ class ViewFinder
11
+ # Initialize a finder
12
+ #
13
+ # @param view [Class] the superclass view
14
+ #
15
+ # @api private
16
+ # @since 0.1.0
17
+ def initialize(view)
18
+ @view = view
19
+ end
20
+
21
+ # Find a view for the given template.
22
+ # It looks up for the current view and its subclasses.
23
+ #
24
+ # @param template [Hanami::View::Template] a template to be associated
25
+ # to a view
26
+ #
27
+ # @return [Class] a view associated with the given template
28
+ #
29
+ # @api private
30
+ # @since 0.1.0
31
+ def find(template)
32
+ @view.subclasses.find {|v| v.format == template.format } || @view
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ require 'tilt'
2
+
3
+ module Hanami
4
+ module View
5
+ # A logic-less template.
6
+ #
7
+ # @since 0.1.0
8
+ class Template
9
+ def initialize(template, encoding = Encoding::UTF_8)
10
+ @_template = Tilt.new(template, nil, default_encoding: encoding)
11
+ end
12
+
13
+ # Returns the format that the template handles.
14
+ #
15
+ # @return [Symbol] the format name
16
+ #
17
+ # @since 0.1.0
18
+ #
19
+ # @example
20
+ # require 'hanami/view'
21
+ #
22
+ # template = Hanami::View::Template.new('index.html.erb')
23
+ # template.format # => :html
24
+ def format
25
+ @_template.basename.match(/\.([^.]+)/).captures.first.to_sym
26
+ end
27
+
28
+ # Render the template within the context of the given scope.
29
+ #
30
+ # @param scope [Hanami::View::Scope] the rendering scope
31
+ #
32
+ # @return [String] the output of the rendering process
33
+ #
34
+ # @api private
35
+ # @since 0.1.0
36
+ #
37
+ # @see Hanami::View::Scope
38
+ def render(scope, &blk)
39
+ @_template.render(scope, {}, &blk)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,8 @@
1
1
  module Hanami
2
2
  module View
3
- VERSION = "0.0.0"
3
+ # Defines the version
4
+ #
5
+ # @since 0.1.0
6
+ VERSION = '0.6.0'.freeze
4
7
  end
5
8
  end
metadata CHANGED
@@ -1,61 +1,135 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
+ - Trung Lê
9
+ - Alfonso Uceda
8
10
  autorequire:
9
- bindir: exe
11
+ bindir: bin
10
12
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
13
+ date: 2016-01-22 00:00:00.000000000 Z
12
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tilt
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.1
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '2.0'
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.1
35
+ - !ruby/object:Gem::Dependency
36
+ name: hanami-utils
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.7'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.7'
13
49
  - !ruby/object:Gem::Dependency
14
50
  name: bundler
15
51
  requirement: !ruby/object:Gem::Requirement
16
52
  requirements:
17
53
  - - "~>"
18
54
  - !ruby/object:Gem::Version
19
- version: '1.11'
55
+ version: '1.5'
20
56
  type: :development
21
57
  prerelease: false
22
58
  version_requirements: !ruby/object:Gem::Requirement
23
59
  requirements:
24
60
  - - "~>"
25
61
  - !ruby/object:Gem::Version
26
- version: '1.11'
62
+ version: '1.5'
63
+ - !ruby/object:Gem::Dependency
64
+ name: minitest
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '5'
27
77
  - !ruby/object:Gem::Dependency
28
78
  name: rake
29
79
  requirement: !ruby/object:Gem::Requirement
30
80
  requirements:
31
81
  - - "~>"
32
82
  - !ruby/object:Gem::Version
33
- version: '10.0'
83
+ version: '10'
34
84
  type: :development
35
85
  prerelease: false
36
86
  version_requirements: !ruby/object:Gem::Requirement
37
87
  requirements:
38
88
  - - "~>"
39
89
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- description: Hanami is a web framework for Ruby
90
+ version: '10'
91
+ description: View layer for Hanami
42
92
  email:
43
93
  - me@lucaguidi.com
94
+ - trung.le@ruby-journal.com
95
+ - uceda73@gmail.com
44
96
  executables: []
45
97
  extensions: []
46
98
  extra_rdoc_files: []
47
99
  files:
48
- - ".gitignore"
49
- - Gemfile
100
+ - CHANGELOG.md
101
+ - LICENSE.md
50
102
  - README.md
51
- - Rakefile
52
- - bin/console
53
- - bin/setup
54
103
  - hanami-view.gemspec
104
+ - lib/hanami-view.rb
105
+ - lib/hanami/layout.rb
106
+ - lib/hanami/presenter.rb
55
107
  - lib/hanami/view.rb
108
+ - lib/hanami/view/configuration.rb
109
+ - lib/hanami/view/dsl.rb
110
+ - lib/hanami/view/errors.rb
111
+ - lib/hanami/view/escape.rb
112
+ - lib/hanami/view/inheritable.rb
113
+ - lib/hanami/view/rendering.rb
114
+ - lib/hanami/view/rendering/layout_finder.rb
115
+ - lib/hanami/view/rendering/layout_registry.rb
116
+ - lib/hanami/view/rendering/layout_scope.rb
117
+ - lib/hanami/view/rendering/null_layout.rb
118
+ - lib/hanami/view/rendering/null_template.rb
119
+ - lib/hanami/view/rendering/partial.rb
120
+ - lib/hanami/view/rendering/partial_finder.rb
121
+ - lib/hanami/view/rendering/registry.rb
122
+ - lib/hanami/view/rendering/scope.rb
123
+ - lib/hanami/view/rendering/template.rb
124
+ - lib/hanami/view/rendering/template_finder.rb
125
+ - lib/hanami/view/rendering/template_name.rb
126
+ - lib/hanami/view/rendering/templates_finder.rb
127
+ - lib/hanami/view/rendering/view_finder.rb
128
+ - lib/hanami/view/template.rb
56
129
  - lib/hanami/view/version.rb
57
130
  homepage: http://hanamirb.org
58
- licenses: []
131
+ licenses:
132
+ - MIT
59
133
  metadata: {}
60
134
  post_install_message:
61
135
  rdoc_options: []
@@ -65,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
139
  requirements:
66
140
  - - ">="
67
141
  - !ruby/object:Gem::Version
68
- version: '0'
142
+ version: 2.0.0
69
143
  required_rubygems_version: !ruby/object:Gem::Requirement
70
144
  requirements:
71
145
  - - ">="
@@ -76,5 +150,6 @@ rubyforge_project:
76
150
  rubygems_version: 2.5.1
77
151
  signing_key:
78
152
  specification_version: 4
79
- summary: The web, with simplicity
153
+ summary: View layer for Hanami, with a separation between views and templates
80
154
  test_files: []
155
+ has_rdoc:
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in hanami-view.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "hanami/view"
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
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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