From 8cecdc2d03d433c8fb68aff5ca0f45cdd2246172 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Tue, 19 Jan 2016 19:18:09 +0100 Subject: [PATCH] Lotus => Hanami --- .travis.yml | 22 +-- CHANGELOG.md | 22 +-- CONTRIBUTING.md | 2 +- Gemfile | 8 +- README.md | 173 +++++++++--------- lotus-view.gemspec => hanami-view.gemspec | 16 +- lib/hanami-view.rb | 1 + lib/{lotus => hanami}/layout.rb | 44 ++--- lib/{lotus => hanami}/presenter.rb | 18 +- lib/{lotus => hanami}/view.rb | 100 +++++----- lib/{lotus => hanami}/view/configuration.rb | 126 ++++++------- lib/{lotus => hanami}/view/dsl.rb | 100 +++++----- lib/{lotus => hanami}/view/errors.rb | 8 +- lib/{lotus => hanami}/view/escape.rb | 38 ++-- lib/{lotus => hanami}/view/inheritable.rb | 8 +- lib/{lotus => hanami}/view/rendering.rb | 90 ++++----- .../view/rendering/layout_finder.rb | 62 +++---- .../view/rendering/layout_registry.rb | 12 +- .../view/rendering/layout_scope.rb | 20 +- .../view/rendering/null_layout.rb | 16 +- .../view/rendering/null_template.rb | 18 +- .../view/rendering/partial.rb | 8 +- .../view/rendering/partial_finder.rb | 12 +- .../view/rendering/registry.rb | 32 ++-- lib/{lotus => hanami}/view/rendering/scope.rb | 14 +- .../view/rendering/template.rb | 10 +- .../view/rendering/template_finder.rb | 14 +- .../view/rendering/template_name.rb | 4 +- .../view/rendering/templates_finder.rb | 18 +- .../view/rendering/view_finder.rb | 6 +- lib/{lotus => hanami}/view/template.rb | 10 +- lib/{lotus => hanami}/view/version.rb | 4 +- lib/lotus-view.rb | 1 - test/escape_test.rb | 2 +- test/fixtures.rb | 68 +++---- test/integration/configuration_test.rb | 6 +- test/integration/framework_freeze_test.rb | 8 +- test/integration/template_name_test.rb | 22 +-- test/layout_test.rb | 16 +- test/load_test.rb | 4 +- test/partial_finder_test.rb | 6 +- test/presenter_test.rb | 2 +- test/rendering_test.rb | 16 +- test/template_test.rb | 8 +- test/test_helper.rb | 16 +- test/version_test.rb | 4 +- test/view/configuration_test.rb | 22 +-- test/view/rendering/layout_scope_test.rb | 8 +- test/view/rendering/scope_test.rb | 14 +- test/view_test.rb | 52 +++--- 50 files changed, 649 insertions(+), 662 deletions(-) rename lotus-view.gemspec => hanami-view.gemspec (66%) create mode 100644 lib/hanami-view.rb rename lib/{lotus => hanami}/layout.rb (70%) rename lib/{lotus => hanami}/presenter.rb (89%) rename lib/{lotus => hanami}/view.rb (70%) rename lib/{lotus => hanami}/view/configuration.rb (78%) rename lib/{lotus => hanami}/view/dsl.rb (78%) rename lib/{lotus => hanami}/view/errors.rb (84%) rename lib/{lotus => hanami}/view/escape.rb (81%) rename lib/{lotus => hanami}/view/inheritable.rb (88%) rename lib/{lotus => hanami}/view/rendering.rb (70%) rename lib/{lotus => hanami}/view/rendering/layout_finder.rb (57%) rename lib/{lotus => hanami}/view/rendering/layout_registry.rb (82%) rename lib/{lotus => hanami}/view/rendering/layout_scope.rb (93%) rename lib/{lotus => hanami}/view/rendering/null_layout.rb (73%) rename lib/{lotus => hanami}/view/rendering/null_template.rb (87%) rename lib/{lotus => hanami}/view/rendering/partial.rb (77%) rename lib/{lotus => hanami}/view/rendering/partial_finder.rb (85%) rename lib/{lotus => hanami}/view/rendering/registry.rb (73%) rename lib/{lotus => hanami}/view/rendering/scope.rb (88%) rename lib/{lotus => hanami}/view/rendering/template.rb (86%) rename lib/{lotus => hanami}/view/rendering/template_finder.rb (75%) rename lib/{lotus => hanami}/view/rendering/template_name.rb (94%) rename lib/{lotus => hanami}/view/rendering/templates_finder.rb (84%) rename lib/{lotus => hanami}/view/rendering/view_finder.rb (84%) rename lib/{lotus => hanami}/view/template.rb (80%) rename lib/{lotus => hanami}/view/version.rb (63%) delete mode 100644 lib/lotus-view.rb diff --git a/.travis.yml b/.travis.yml index 7fff5cc9..04b4b5fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,27 +11,13 @@ script: - 'bundle install' - 'bundle exec rake test:coverage' rvm: - - 2.0.0 - - 2.1.0 - - 2.1.1 - - 2.1.2 - - 2.1.3 - - 2.1.4 - - 2.1.5 - - 2.1.6 - - 2.1.7 - - 2.1.8 - - 2.2.0 - - 2.2.1 - - 2.2.2 - - 2.2.3 - - 2.2.4 - - 2.3.0 + - 2.2 + - 2.3 + - ruby-head - jruby-9000 - jruby-head - - rbx-2 matrix: allow_failures: - - rvm: rbx-2 + - rvm: ruby-head - rvm: jruby-head diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af0cd3a..aa576295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,17 @@ -# Lotus::View -View layer for Lotus +# Hanami::View +View layer for Hanami ## v0.5.0 - 2016-01-12 ### Added -- [Luca Guidi] Added `Lotus::View::Configuration#default_encoding` to set the encoding for templates +- [Luca Guidi] Added `Hanami::View::Configuration#default_encoding` to set the encoding for templates ### Fixed - [Luca Guidi] Let exceptions to be raised as they occur in rendering context. This fixes misleading backtraces for exceptions. -- [Martin Rubi] Raise a `Lotus::View::MissingTemplateError` when rendering a missing partial from a template +- [Martin Rubi] Raise a `Hanami::View::MissingTemplateError` when rendering a missing partial from a template - [Luca Guidi] Fix for `template.erb is not valid US-ASCII (Encoding::InvalidByteSequenceError)` when system encoding is not set ### Changed -- [Liam Dawson] Introduced `Lotus::View::Error` and let all the framework exceptions to inherit from it. +- [Liam Dawson] Introduced `Hanami::View::Error` and let all the framework exceptions to inherit from it. ## v0.4.4 - 2015-09-30 ### Added @@ -43,10 +43,10 @@ View layer for Lotus - [Trung Lê] When duplicate the framework, also duplicate `Presenter` - [Benny Klotz] Introduced `Scope#class`, `#inspect`, `LayoutScope#class` and `#inspect` - [Alfonso Uceda Pompa & Trung Lê] Introduced `Configuration#prepare` -- [Luca Guidi] Implemented "respond to" logic for `Lotus::View::Scope` (`respond_to?` and `respond_to_missing?`) -- [Luca Guidi] Implemented "respond to" logic for `Lotus::Layout` (`respond_to?` and `respond_to_missing?`) +- [Luca Guidi] Implemented "respond to" logic for `Hanami::View::Scope` (`respond_to?` and `respond_to_missing?`) +- [Luca Guidi] Implemented "respond to" logic for `Hanami::Layout` (`respond_to?` and `respond_to_missing?`) - [Jeremy Stephens] Allow view concrete methods that accept a block to be invoked from templates -- [Peter Suschlik] Implemented "respond to" logic for `Lotus::Presenter` (`respond_to?` and `respond_to_missing?`) +- [Peter Suschlik] Implemented "respond to" logic for `Hanami::Presenter` (`respond_to?` and `respond_to_missing?`) - [Luca Guidi] Official support for Ruby 2.2 ### Changed @@ -63,7 +63,7 @@ View layer for Lotus - [Luca Guidi] Introduced `Configuration#layout` to define the layout that all the views will use - [Luca Guidi] Introduced `Configuration#load_paths` to define several sources where to lookup for templates - [Luca Guidi] Introduced `Configuration#root` to define the root path where to find templates -- [Luca Guidi] Introduced `Lotus::View::Configuration` +- [Luca Guidi] Introduced `Hanami::View::Configuration` - [Grant Ammons] Allow view concrete methods with arity > 0 to be invoked from templates - [Luca Guidi] Official support for Ruby 2.1 @@ -78,11 +78,11 @@ View layer for Lotus ## v0.1.0 - 2014-03-23 ### Added - [Luca Guidi] Allow custom rendering policy via `Action#render` override. This bypasses the template lookup and rendering. -- [Luca Guidi] Introduced `Lotus::Presenter` +- [Luca Guidi] Introduced `Hanami::Presenter` - [Luca Guidi] Introduced templates rendering from templates and layouts - [Luca Guidi] Introduced partials rendering from templates and layouts - [Luca Guidi] Introduced layouts support -- [Luca Guidi] Introduced `Lotus::View.load!` as entry point to load views and templates +- [Luca Guidi] Introduced `Hanami::View.load!` as entry point to load views and templates - [Luca Guidi] Allow to setup template name via `View.template` - [Luca Guidi] Rendering context also considers locals passed to the constructor - [Luca Guidi] Introduced `View.format` as DSL to declare which format to handle diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e18bdc37..70f01b1c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ Here are some ways *you* can contribute: * by closing [issues][] * by reviewing patches -[issues]: https://github.com/lotus/view/issues +[issues]: https://github.com/hanami/view/issues ## Submitting an Issue We use the [GitHub issue tracker][issues] to track bugs and features. Before diff --git a/Gemfile b/Gemfile index 1060551c..41b22b9a 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ unless ENV['TRAVIS'] gem 'yard', require: false end -gem 'lotus-utils', '~> 0.6', require: false, github: 'lotus/utils', branch: '0.6.x' -gem 'haml', require: false -gem 'simplecov', require: false -gem 'coveralls', require: false +gem 'hanami-utils', '~> 0.7', require: false, github: 'hanami/utils', branch: '0.7.x' +gem 'haml', require: false +gem 'simplecov', require: false +gem 'coveralls', require: false diff --git a/README.md b/README.md index 9fb0eb64..ec12bc76 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Lotus::View +# Hanami::View -A View layer for [Lotus](http://lotusrb.org). +A View layer for [Hanami](http://hanamirb.org). It's based on a **separation between views and templates**. @@ -12,36 +12,36 @@ Keeping things separated helps to declutter templates and models from presentati Also, since views are objects, they are easily testable. If you ever used [Mustache](http://mustache.github.io/), you are already aware of the advantages. -Like all the other Lotus components, it can be used as a standalone framework or within a full Lotus application. +Like all the other Hanami components, it can be used as a standalone framework or within a full Hanami application. ## Status -[![Gem Version](http://img.shields.io/gem/v/lotus-view.svg)](https://badge.fury.io/rb/lotus-view) -[![Build Status](http://img.shields.io/travis/lotus/view/master.svg)](https://travis-ci.org/lotus/view?branch=master) -[![Coverage](http://img.shields.io/coveralls/lotus/view/master.svg)](https://coveralls.io/r/lotus/view) -[![Code Climate](http://img.shields.io/codeclimate/github/lotus/view.svg)](https://codeclimate.com/github/lotus/view) -[![Dependencies](http://img.shields.io/gemnasium/lotus/view.svg)](https://gemnasium.com/lotus/view) -[![Inline docs](http://inch-ci.org/github/lotus/view.svg?branch=master)](http://inch-ci.org/github/lotus/view) +[![Gem Version](http://img.shields.io/gem/v/hanami-view.svg)](https://badge.fury.io/rb/hanami-view) +[![Build Status](http://img.shields.io/travis/hanami/view/master.svg)](https://travis-ci.org/hanami/view?branch=master) +[![Coverage](http://img.shields.io/coveralls/hanami/view/master.svg)](https://coveralls.io/r/hanami/view) +[![Code Climate](http://img.shields.io/codeclimate/github/hanami/view.svg)](https://codeclimate.com/github/hanami/view) +[![Dependencies](http://img.shields.io/gemnasium/hanami/view.svg)](https://gemnasium.com/hanami/view) +[![Inline docs](http://inch-ci.org/github/hanami/view.svg?branch=master)](http://inch-ci.org/github/hanami/view) ## Contact -* Home page: http://lotusrb.org -* Mailing List: http://lotusrb.org/mailing-list -* API Doc: http://rdoc.info/gems/lotus-view -* Bugs/Issues: https://github.com/lotus/view/issues -* Support: http://stackoverflow.com/questions/tagged/lotus-ruby -* Chat: https://gitter.im/lotus/chat +* Home page: http://hanamirb.org +* Mailing List: http://hanamirb.org/mailing-list +* API Doc: http://rdoc.info/gems/hanami-view +* Bugs/Issues: https://github.com/hanami/view/issues +* Support: http://stackoverflow.com/questions/tagged/hanami +* Chat: http://chat.hanamirb.org ## Rubies -__Lotus::View__ supports Ruby (MRI) 2+ +__Hanami::View__ supports Ruby (MRI) 2+ ## Installation Add this line to your application's Gemfile: ```ruby -gem 'lotus-view' +gem 'hanami-view' ``` And then execute: @@ -50,27 +50,27 @@ And then execute: Or install it yourself as: - $ gem install lotus-view + $ gem install hanami-view ## Usage ### Conventions - * Templates are searched under `Lotus::View.configuration.root`, set this value according to your app structure (eg. `"app/templates"`). + * Templates are searched under `Hanami::View.configuration.root`, set this value according to your app structure (eg. `"app/templates"`). * A view will look for a template with a file name that is composed by its full class name (eg. `"articles/index"`). * A template must have two concatenated extensions: one for the format and one for the engine (eg. `".html.erb"`). - * The framework must be loaded before rendering the first time: `Lotus::View.load!`. + * The framework must be loaded before rendering the first time: `Hanami::View.load!`. ### Views A simple view looks like this: ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Index - include Lotus::View + include Hanami::View end end ``` @@ -78,22 +78,22 @@ end Suppose that we want to render a list of `articles`: ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Index - include Lotus::View + include Hanami::View end end -Lotus::View.configure do +Hanami::View.configure do root 'app/templates' end -Lotus::View.load! +Hanami::View.load! -path = Lotus::View.configuration.root.join('articles/index.html.erb') -template = Lotus::View::Template.new(path) +path = Hanami::View.configuration.root.join('articles/index.html.erb') +template = Hanami::View::Template.new(path) articles = ArticleRepository.all Articles::Index.new(template, articles: articles).render @@ -103,11 +103,11 @@ While this code is working fine, it's inefficient and verbose, because we are lo Also, this is strictly related to the HTML format, what if we want to manage other formats? ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Index - include Lotus::View + include Hanami::View end class AtomIndex < Index @@ -115,11 +115,11 @@ module Articles end end -Lotus::View.configure do +Hanami::View.configure do root 'app/templates' end -Lotus::View.load! +Hanami::View.load! articles = ArticleRepository.all @@ -132,7 +132,7 @@ Articles::Index.render(format: :atom, articles: articles) # and "articles/index.atom.erb" Articles::Index.render(format: :xml, articles: articles) - # => This will raise a Lotus::View::MissingTemplateError + # => This will raise a Hanami::View::MissingTemplateError ``` ### Locals @@ -140,11 +140,11 @@ Articles::Index.render(format: :xml, articles: articles) All the objects passed in the context are called _locals_, they are available both in the view and in the template: ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Show - include Lotus::View + include Hanami::View def authors article.authors.map(&:full_name).join ', ' @@ -169,11 +169,11 @@ All the methods defined in the view are accessible from the template: For convenience, they are also available to the view as a Hash, accessed through the `locals` method. ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Show - include Lotus::View + include Hanami::View # This view already responds to `#article` because there is an element in # the locals with the same key. @@ -200,11 +200,11 @@ end Since a view is an object, you can override `#render` and provide your own rendering policy: ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Show - include Lotus::View + include Hanami::View format :json def render @@ -224,11 +224,11 @@ The `.format` DSL is used to declare one or more mime types that a view is able These values are **arbitrary**, just **be sure to create a corresponding template**. ```ruby -require 'lotus/view' +require 'hanami/view' module Articles class Show - include Lotus::View + include Hanami::View format :custom end end @@ -240,16 +240,16 @@ Articles::Show.render({format: :custom, article: article}) ### Engines The builtin rendering engine is [ERb](http://en.wikipedia.org/wiki/ERuby). -However, Lotus::View supports countless rendering engines out of the box. -Require your library of choice **before** requiring `'lotus/view'`, and it will just work. +However, Hanami::View supports countless rendering engines out of the box. +Require your library of choice **before** requiring `'hanami/view'`, and it will just work. ```ruby require 'haml' -require 'lotus/view' +require 'hanami/view' module Articles class Show - include Lotus::View + include Hanami::View end end @@ -382,11 +382,11 @@ For instance, if [ERubis](http://www.kuwata-lab.com/erubis/) is loaded, it will ### Root -Template lookup is performed under the `Lotus::View.configuration.root` directory. You can specify a different path on a per view basis: +Template lookup is performed under the `Hanami::View.configuration.root` directory. You can specify a different path on a per view basis: ```ruby class ViewWithDifferentRoot - include Lotus::View + include Hanami::View root 'path/to/root' end @@ -397,7 +397,7 @@ end The template file must be located under the relevant `root` and must match the class name: ```ruby -puts Lotus::View.configuration.root # => # +puts Hanami::View.configuration.root # => # Articles::Index.template # => "articles/index" ``` @@ -406,7 +406,7 @@ Each view can specify a different template: ```ruby module Articles class Create - include Lotus::View + include Hanami::View template 'articles/new' end @@ -441,7 +441,7 @@ Layouts are wrappers for views. Layouts may serve to reuse common markup. ```ruby class ApplicationLayout - include Lotus::Layout + include Hanami::Layout def page_title 'Title:' @@ -450,7 +450,7 @@ end module Articles class Index - include Lotus::View + include Hanami::View layout :application def page_title @@ -468,7 +468,7 @@ Articles::Index.render(format: :html) # => Will use ApplicationLayout Articles::Index.render(format: :rss) # => Will use nothing ``` -As per convention, layout templates are located under `Lotus::View.root` or `ApplicationLayout.root` and use the underscored name (eg. `ApplicationLayout => application.html.erb`). +As per convention, layout templates are located under `Hanami::View.root` or `ApplicationLayout.root` and use the underscored name (eg. `ApplicationLayout => application.html.erb`). ### Optional Content @@ -497,11 +497,11 @@ In the other case, `content` returns `nil`. ```ruby module Products class Index - include Lotus::View + include Hanami::View end class Show - include Lotus::View + include Hanami::View def footer "contents for footer" @@ -528,7 +528,7 @@ class Map end class MapPresenter - include Lotus::Presenter + include Hanami::Presenter def count locations.count @@ -561,13 +561,13 @@ puts presenter.inspect_object # => # # +Hanami::View.configuration.root # => # Show.root # => # ``` ### Reusability -__Lotus::View__ can be used as a singleton framework as seen in this README. -The application code includes `Lotus::View` or `Lotus::Layout` directly +__Hanami::View__ can be used as a singleton framework as seen in this README. +The application code includes `Hanami::View` or `Hanami::Layout` directly and the configuration is unique per Ruby process. While this is convenient for tiny applications, it doesn't fit well for more complex scenarios, where we want micro applications to coexist together. ```ruby -require 'lotus/view' +require 'hanami/view' -Lotus::View.configure do +Hanami::View.configure do root '/path/to/root' end module WebApp - View = Lotus::View.duplicate(self) + View = Hanami::View.duplicate(self) end module ApiApp - View = Lotus::View.duplicate(self) do + View = Hanami::View.duplicate(self) do root '/another/root' end end -Lotus::View.configuration.root # => # -WebApp::View.configuration.root # => #, inherited from Lotus::View +Hanami::View.configuration.root # => # +WebApp::View.configuration.root # => #, inherited from Hanami::View ApiApp::View.configuration.root # => # ``` @@ -656,39 +656,39 @@ configuration. ### Thread safety -__Lotus::View__ is thread safe during the runtime, but it isn't during the loading process. +__Hanami::View__ is thread safe during the runtime, but it isn't during the loading process. Please load the framework as the last thing before your application starts. Also, be sure that your app provides a thread safe context while it's loaded. ```ruby Mutex.new.synchronize do - Lotus::View.load! + Hanami::View.load! end ``` After this operation, all the class variables are frozen, in order to prevent accidental modifications at the run time. -**This is not necessary, when Lotus::View is used within a Lotus application.** +**This is not necessary, when Hanami::View is used within a Hanami application.** ### Security The output of views and presenters is always **autoescaped**. **ATTENTION:** In order to prevent XSS attacks, please read the instructions below. -Because Lotus::View supports a lot of template engines, the escape happens at the level of the view. +Because Hanami::View supports a lot of template engines, the escape happens at the level of the view. Most of the time everything happens automatically, but there are still some corner cases that need your manual intervention. #### View autoescape ```ruby -require 'lotus/view' +require 'hanami/view' User = Struct.new(:name) module Users class Show - include Lotus::View + include Hanami::View def user_name user.name @@ -702,7 +702,7 @@ end user = User.new("") # THIS IS USEFUL FOR UNIT TESTING: -template = Lotus::View::Template.new('users/show.html.erb') +template = Hanami::View::Template.new('users/show.html.erb') view = Users::Show.new(template, user: user) view.user_name # => "<script>alert('xss')</script>" @@ -714,12 +714,12 @@ Users::Show.render(format: :html, user: user) #### Presenter autoescape ```ruby -require 'lotus/view' +require 'hanami/view' User = Struct.new(:name) class UserPresenter - include Lotus::Presenter + include Hanami::Presenter end user = User.new("") @@ -744,13 +744,13 @@ You have two alternatives: Both those solutions allow you to keep the template syntax unchanged, but to have a safer output. ```ruby -require 'lotus/view' +require 'hanami/view' User = Struct.new(:first_name, :last_name) module Users class Show - include Lotus::View + include Hanami::View def user _escape locals[:user] @@ -791,13 +791,13 @@ Please note that **this may open your application to XSS attacks.** #### Raw contents in views ```ruby -require 'lotus/view' +require 'hanami/view' User = Struct.new(:name) module Users class Show - include Lotus::View + include Hanami::View def user_name _raw user.name @@ -818,12 +818,12 @@ html #### Raw contents in presenters ```ruby -require 'lotus/view' +require 'hanami/view' User = Struct.new(:name) class UserPresenter - include Lotus::Presenter + include Hanami::Presenter def first_name _raw @object.first_name @@ -838,7 +838,7 @@ presenter.name # => "" ## Versioning -__Lotus::View__ uses [Semantic Versioning 2.0.0](http://semver.org) +__Hanami::View__ uses [Semantic Versioning 2.0.0](http://semver.org) ## Contributing @@ -851,3 +851,4 @@ __Lotus::View__ uses [Semantic Versioning 2.0.0](http://semver.org) ## Copyright Copyright 2014-2016 Luca Guidi – Released under MIT License +This project was formerly known as Lotus (`lotus-view`). diff --git a/lotus-view.gemspec b/hanami-view.gemspec similarity index 66% rename from lotus-view.gemspec rename to hanami-view.gemspec index 24b7bca7..990bd26c 100644 --- a/lotus-view.gemspec +++ b/hanami-view.gemspec @@ -1,26 +1,26 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'lotus/view/version' +require 'hanami/view/version' Gem::Specification.new do |spec| - spec.name = 'lotus-view' - spec.version = Lotus::View::VERSION + spec.name = 'hanami-view' + spec.version = Hanami::View::VERSION spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda'] spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com'] - spec.description = %q{View layer for Lotus} - spec.summary = %q{View layer for Lotus, with a separation between views and templates} - spec.homepage = 'http://lotusrb.org' + spec.description = %q{View layer for Hanami} + spec.summary = %q{View layer for Hanami, with a separation between views and templates} + spec.homepage = 'http://hanamirb.org' spec.license = 'MIT' - spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md lotus-view.gemspec`.split($/) + spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-view.gemspec`.split($/) spec.executables = [] spec.test_files = spec.files.grep(%r{^(test)/}) spec.require_paths = ['lib'] spec.required_ruby_version = '>= 2.0.0' spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.1' - spec.add_runtime_dependency 'lotus-utils', '~> 0.6' + spec.add_runtime_dependency 'hanami-utils', '~> 0.6' spec.add_development_dependency 'bundler', '~> 1.5' spec.add_development_dependency 'minitest', '~> 5' diff --git a/lib/hanami-view.rb b/lib/hanami-view.rb new file mode 100644 index 00000000..cc9f6abf --- /dev/null +++ b/lib/hanami-view.rb @@ -0,0 +1 @@ +require 'hanami/view' diff --git a/lib/lotus/layout.rb b/lib/hanami/layout.rb similarity index 70% rename from lib/lotus/layout.rb rename to lib/hanami/layout.rb index 0908dfe6..e7be0ffe 100644 --- a/lib/lotus/layout.rb +++ b/lib/hanami/layout.rb @@ -1,14 +1,14 @@ -require 'lotus/utils/class_attribute' -require 'lotus/view/rendering/layout_registry' -require 'lotus/view/rendering/layout_scope' -require 'lotus/view/rendering/null_layout' +require 'hanami/utils/class_attribute' +require 'hanami/view/rendering/layout_registry' +require 'hanami/view/rendering/layout_scope' +require 'hanami/view/rendering/null_layout' -module Lotus +module Hanami # Layout # # @since 0.1.0 # - # @see Lotus::Layout::ClassMethods + # @see Hanami::Layout::ClassMethods module Layout # Register a layout # @@ -16,17 +16,17 @@ module Layout # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end def self.included(base) - conf = Lotus::View::Configuration.for(base) + conf = Hanami::View::Configuration.for(base) conf.add_layout(base) base.class_eval do - extend Lotus::View::Dsl.dup + extend Hanami::View::Dsl.dup extend ClassMethods include Utils::ClassAttribute @@ -47,8 +47,8 @@ module ClassMethods # @api private # @since 0.1.0 # - # @see Lotus::Layout::ClassMethods#suffix - # @see Lotus::Layout::ClassMethods#template + # @see Hanami::Layout::ClassMethods#suffix + # @see Hanami::Layout::ClassMethods#template SUFFIX = '_layout'.freeze # A registry that holds all the registered layouts. @@ -56,7 +56,7 @@ module ClassMethods # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::LayoutRegistry + # @see Hanami::View::Rendering::LayoutRegistry def registry @registry ||= View::Rendering::LayoutRegistry.new(self) end @@ -66,14 +66,14 @@ def registry # @api private # @since 0.1.0 # - # @see Lotus::Layout::ClassMethods#SUFFIX - # @see Lotus::Layout::ClassMethods#suffix + # @see Hanami::Layout::ClassMethods#SUFFIX + # @see Hanami::Layout::ClassMethods#suffix # # @example # # Given a template 'templates/application.html.erb' # # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end # # ApplicationLayout.template # => 'application' @@ -86,8 +86,8 @@ def template # @api private # @since 0.1.0 # - # @see Lotus::Layout::ClassMethods#SUFFIX - # @see Lotus::Layout::ClassMethods#template + # @see Hanami::Layout::ClassMethods#SUFFIX + # @see Hanami::Layout::ClassMethods#template def suffix SUFFIX end @@ -98,7 +98,7 @@ def suffix # @api private # @since 0.1.0 # - # @see Lotus::View.load! + # @see Hanami::View.load! def load! registry.freeze configuration.freeze @@ -107,13 +107,13 @@ def load! # Initialize a layout # - # @param scope [Lotus::View::Rendering::Scope] view rendering scope + # @param scope [Hanami::View::Rendering::Scope] view rendering scope # @param rendered [String] the output of the view rendering process # # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering#render + # @see Hanami::View::Rendering#render def initialize(scope, rendered) @scope, @rendered = View::Rendering::LayoutScope.new(self, scope), rendered end @@ -125,7 +125,7 @@ def initialize(scope, rendered) # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering#render + # @see Hanami::View::Rendering#render def render template.render(@scope, &Proc.new{@rendered}) end diff --git a/lib/lotus/presenter.rb b/lib/hanami/presenter.rb similarity index 89% rename from lib/lotus/presenter.rb rename to lib/hanami/presenter.rb index 5c7ee9c5..be2b19d0 100644 --- a/lib/lotus/presenter.rb +++ b/lib/hanami/presenter.rb @@ -1,6 +1,6 @@ -require 'lotus/view/escape' +require 'hanami/view/escape' -module Lotus +module Hanami # Presenter pattern implementation # # It delegates to the wrapped object the missing method invocations. @@ -10,7 +10,7 @@ module Lotus # @since 0.1.0 # # @example Basic usage - # require 'lotus/view' + # require 'hanami/view' # # class Map # attr_reader :locations @@ -25,7 +25,7 @@ module Lotus # end # # class MapPresenter - # include Lotus::Presenter + # include Hanami::Presenter # # def count # locations.count @@ -56,12 +56,12 @@ module Lotus # puts presenter.inspect_object # => # # # @example Escape - # require 'lotus/view' + # require 'hanami/view' # # User = Struct.new(:first_name, :last_name) # # class UserPresenter - # include Lotus::Presenter + # include Hanami::Presenter # # def full_name # [first_name, last_name].join(' ') @@ -88,9 +88,9 @@ module Presenter # @since 0.4.0 # @api private # - # @see Lotus::View::Escape + # @see Hanami::View::Escape def self.included(base) - base.extend ::Lotus::View::Escape + base.extend ::Hanami::View::Escape end # Initialize the presenter @@ -109,7 +109,7 @@ def initialize(object) # @since 0.1.0 def method_missing(m, *args, &blk) if @object.respond_to?(m) - ::Lotus::View::Escape.html(@object.__send__(m, *args, &blk)) + ::Hanami::View::Escape.html(@object.__send__(m, *args, &blk)) else super end diff --git a/lib/lotus/view.rb b/lib/hanami/view.rb similarity index 70% rename from lib/lotus/view.rb rename to lib/hanami/view.rb index 05739801..81cf1465 100644 --- a/lib/lotus/view.rb +++ b/lib/hanami/view.rb @@ -1,17 +1,17 @@ require 'set' require 'pathname' -require 'lotus/utils/class_attribute' -require 'lotus/view/version' -require 'lotus/view/configuration' -require 'lotus/view/inheritable' -require 'lotus/view/rendering' -require 'lotus/view/escape' -require 'lotus/view/dsl' -require 'lotus/view/errors' -require 'lotus/layout' -require 'lotus/presenter' +require 'hanami/utils/class_attribute' +require 'hanami/view/version' +require 'hanami/view/configuration' +require 'hanami/view/inheritable' +require 'hanami/view/rendering' +require 'hanami/view/escape' +require 'hanami/view/dsl' +require 'hanami/view/errors' +require 'hanami/layout' +require 'hanami/presenter' -module Lotus +module Hanami # View # # @since 0.1.0 @@ -31,61 +31,61 @@ module View # # @since 0.2.0 # - # @see Lotus::View::Configuration + # @see Hanami::View::Configuration # # @example - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # root '/path/to/root' # end def self.configure(&blk) configuration.instance_eval(&blk) end - # Duplicate Lotus::View in order to create a new separated instance + # Duplicate Hanami::View in order to create a new separated instance # of the framework. # # The new instance of the framework will be completely decoupled from the # original. It will inherit the configuration, but all the changes that # happen after the duplication, won't be reflected on the other copies. # - # @return [Module] a copy of Lotus::View + # @return [Module] a copy of Hanami::View # # @since 0.2.0 # @api private # # @example Basic usage - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.dupe + # View = Hanami::View.dupe # end # - # MyApp::View == Lotus::View # => false + # MyApp::View == Hanami::View # => false # # MyApp::View.configuration == - # Lotus::View.configuration # => false + # Hanami::View.configuration # => false # # @example Inheriting configuration - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # root '/path/to/root' # end # # module MyApp - # View = Lotus::View.dupe + # View = Hanami::View.dupe # end # # module MyApi - # View = Lotus::View.dupe + # View = Hanami::View.dupe # View.configure do # root '/another/root' # end # end # - # Lotus::View.configuration.root # => # + # Hanami::View.configuration.root # => # # MyApp::View.configuration.root # => # # MyApi::View.configuration.root # => # def self.dupe @@ -101,19 +101,19 @@ def self.dupe # views will live # @param blk [Proc] an optional block to configure the framework # - # @return [Module] a copy of Lotus::View + # @return [Module] a copy of Hanami::View # # @since 0.2.0 # - # @see Lotus::View#dupe - # @see Lotus::View::Configuration - # @see Lotus::View::Configuration#namespace + # @see Hanami::View#dupe + # @see Hanami::View::Configuration + # @see Hanami::View::Configuration#namespace # # @example Basic usage - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self) + # View = Hanami::View.duplicate(self) # end # # # It will: @@ -131,10 +131,10 @@ def self.dupe # end # # @example Compare code - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self) do + # View = Hanami::View.duplicate(self) do # # ... # end # end @@ -142,8 +142,8 @@ def self.dupe # # it's equivalent to: # # module MyApp - # View = Lotus::View.dupe - # Layout = Lotus::Layout.dup + # View = Hanami::View.dupe + # Layout = Hanami::Layout.dup # # module Views # end @@ -158,10 +158,10 @@ def self.dupe # end # # @example Custom views module - # require 'lotus/view + # require 'hanami/view # # module MyApp - # View = Lotus::View.duplicate(self, 'Vs') + # View = Hanami::View.duplicate(self, 'Vs') # end # # defined?(MyApp::Views) # => nil @@ -173,10 +173,10 @@ def self.dupe # end # # @example Nil views module - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self, nil) + # View = Hanami::View.duplicate(self, nil) # end # # defined?(MyApp::Views) # => nil @@ -187,22 +187,22 @@ def self.dupe # end # # @example Block usage - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self) do + # View = Hanami::View.duplicate(self) do # root '/path/to/root' # end # end # - # Lotus::View.configuration.root # => # + # Hanami::View.configuration.root # => # # MyApp::View.configuration.root # => # def self.duplicate(mod, views = 'Views', &blk) dupe.tap do |duplicated| mod.module_eval %{ module #{ views }; end } if views mod.module_eval %{ - Layout = Lotus::Layout.dup - Presenter = Lotus::Presenter.dup + Layout = Hanami::Layout.dup + Presenter = Hanami::Presenter.dup } duplicated.configure do @@ -214,7 +214,7 @@ def self.duplicate(mod, views = 'Views', &blk) end # Override Ruby's hook for modules. - # It includes basic Lotus::View modules to the given Class. + # It includes basic Hanami::View modules to the given Class. # It sets a copy of the framework configuration # # @param base [Class] the target view @@ -224,15 +224,15 @@ def self.duplicate(mod, views = 'Views', &blk) # # @see http://www.ruby-doc.org/core-2.1.2/Module.html#method-i-included # - # @see Lotus::View::Dsl - # @see Lotus::View::Inheritable - # @see Lotus::View::Rendering + # @see Hanami::View::Dsl + # @see Hanami::View::Inheritable + # @see Hanami::View::Rendering # # @example - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # end def self.included(base) conf = self.configuration diff --git a/lib/lotus/view/configuration.rb b/lib/hanami/view/configuration.rb similarity index 78% rename from lib/lotus/view/configuration.rb rename to lib/hanami/view/configuration.rb index 979fba2c..809a0c22 100644 --- a/lib/lotus/view/configuration.rb +++ b/lib/hanami/view/configuration.rb @@ -1,18 +1,18 @@ require 'set' -require 'lotus/utils/class' -require 'lotus/utils/kernel' -require 'lotus/utils/string' -require 'lotus/utils/load_paths' -require 'lotus/view/rendering/layout_finder' +require 'hanami/utils/class' +require 'hanami/utils/kernel' +require 'hanami/utils/string' +require 'hanami/utils/load_paths' +require 'hanami/view/rendering/layout_finder' -module Lotus +module Hanami module View # Configuration for the framework, controllers and actions. # - # Lotus::Controller has its own global configuration that can be manipulated - # via `Lotus::View.configure`. + # Hanami::Controller has its own global configuration that can be manipulated + # via `Hanami::View.configure`. # - # Every time that `Lotus::View` and `Lotus::Layout` are included, that + # Every time that `Hanami::View` and `Hanami::Layout` are included, that # global configuration is being copied to the recipient. The copy will # inherit all the settings from the original, but all the subsequent changes # aren't reflected from the parent to the children, and viceversa. @@ -43,33 +43,33 @@ class Configuration # Return the original configuration of the framework instance associated # with the given class. # - # When multiple instances of Lotus::View are used in the same application, + # When multiple instances of Hanami::View are used in the same application, # we want to make sure that a controller or an action will receive the # expected configuration. # # @param base [Class] a view or a layout # - # @return [Lotus::Controller::Configuration] the configuration associated + # @return [Hanami::Controller::Configuration] the configuration associated # to the given class. # # @since 0.2.0 # @api private # # @example Direct usage of the framework - # require 'lotus/view' + # require 'hanami/view' # # class Show - # include Lotus::View + # include Hanami::View # end # - # Lotus::View::Configuration.for(Show) - # # => will return from Lotus::View + # Hanami::View::Configuration.for(Show) + # # => will return from Hanami::View # # @example Multiple instances of the framework - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self) + # View = Hanami::View.duplicate(self) # # module Views::Dashboard # class Index @@ -79,24 +79,24 @@ class Configuration # end # # class Show - # include Lotus::Action + # include Hanami::Action # end # - # Lotus::View::Configuration.for(Show) - # # => will return from Lotus::View + # Hanami::View::Configuration.for(Show) + # # => will return from Hanami::View # - # Lotus::View::Configuration.for(MyApp::Views::Dashboard::Index) + # Hanami::View::Configuration.for(MyApp::Views::Dashboard::Index) # # => will return from MyApp::View def self.for(base) - # TODO this implementation is similar to Lotus::Controller::Configuration consider to extract it into Lotus::Utils + # TODO this implementation is similar to Hanami::Controller::Configuration consider to extract it into Hanami::Utils namespace = Utils::String.new(base).namespace - framework = Utils::Class.load_from_pattern!("(#{namespace}|Lotus)::View") + framework = Utils::Class.load_from_pattern!("(#{namespace}|Hanami)::View") framework.configuration end # Initialize a configuration instance # - # @return [Lotus::View::Configuration] a new configuration's instance + # @return [Hanami::View::Configuration] a new configuration's instance # # @since 0.2.0 def initialize @@ -127,14 +127,14 @@ def initialize # @since 0.2.0 # # @example Getting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configuration.namespace # => Object + # Hanami::View.configuration.namespace # => Object # # @example Setting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # namespace 'MyApp::Views' # end def namespace(value = nil) @@ -165,23 +165,23 @@ def namespace(value = nil) # # @since 0.2.0 # - # @see Lotus::View::Dsl#root + # @see Hanami::View::Dsl#root # @see http://www.ruby-doc.org/stdlib-2.1.2/libdoc/pathname/rdoc/Pathname.html - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Pathname-class_method + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Pathname-class_method # # @example Getting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configuration.root # => # + # Hanami::View.configuration.root # => # # # @example Setting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # root '/path/to/templates' # end # - # Lotus::View.configuration.root # => # + # Hanami::View.configuration.root # => # def root(value = nil) if value @root = Utils::Kernel.Pathname(value).realpath @@ -193,7 +193,7 @@ def root(value = nil) # Set the global layout # # If not set, this value defaults to `nil`, while at the rendering time - # it will use `Lotus::View::Rendering::NullLayout`. + # it will use `Hanami::View::Rendering::NullLayout`. # # This is part of a DSL, for this reason when this method is called with # an argument, it will set the corresponding instance variable. When @@ -209,27 +209,27 @@ def root(value = nil) # # @since 0.2.0 # - # @see Lotus::View::Dsl#layout + # @see Hanami::View::Dsl#layout # # @example Getting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configuration.layout # => nil + # Hanami::View.configuration.layout # => nil # # @example Setting the value - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # layout :application # end # - # Lotus::View.configuration.layout # => ApplicationLayout + # Hanami::View.configuration.layout # => ApplicationLayout # # @example Setting the value in a namespaced app - # require 'lotus/view' + # require 'hanami/view' # # module MyApp - # View = Lotus::View.duplicate(self) do + # View = Hanami::View.duplicate(self) do # layout :application # end # end @@ -263,23 +263,23 @@ def layout(value = nil) # @since 0.5.0 # # @example Set UTF-8 As A String - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # default_encoding 'utf-8' # end # # @example Set UTF-8 As An Encoding Constant - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # default_encoding Encoding::UTF_8 # end # # @example Raise An Error For Unknown Encoding - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # default_encoding 'foo' # end # @@ -294,7 +294,7 @@ def default_encoding(value = nil) # Prepare the views. # - # The given block will be yielded when `Lotus::View` will be included by + # The given block will be yielded when `Hanami::View` will be included by # a view. # # This method can be called multiple times. @@ -307,11 +307,11 @@ def default_encoding(value = nil) # # @since 0.3.0 # - # @see Lotus::View.configure - # @see Lotus::View.duplicate + # @see Hanami::View.configure + # @see Hanami::View.duplicate # # @example Including shared utilities - # require 'lotus/view' + # require 'hanami/view' # # module UrlHelpers # def comments_path @@ -319,19 +319,19 @@ def default_encoding(value = nil) # end # end # - # Lotus::View.configure do + # Hanami::View.configure do # prepare do # include UrlHelpers # end # end # - # Lotus::View.load! + # Hanami::View.load! # # module Comments # class New # # The following include will cause UrlHelpers to be included too. # # This makes `comments_path` available in the view context - # include Lotus::View + # include Hanami::View # # def form # %(
) @@ -340,9 +340,9 @@ def default_encoding(value = nil) # end # # @example Preparing multiple times - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View.configure do + # Hanami::View.configure do # prepare do # include UrlHelpers # end @@ -352,13 +352,13 @@ def default_encoding(value = nil) # end # end # - # Lotus::View.configure do + # Hanami::View.configure do # prepare do # include FormattingHelpers # end # end # - # Lotus::View.load! + # Hanami::View.load! # # module Articles # class Index @@ -367,7 +367,7 @@ def default_encoding(value = nil) # # * FormattingHelpers # # # # It also sets the view to render only JSON - # include Lotus::View + # include Hanami::View # end # end def prepare(&blk) @@ -396,7 +396,7 @@ def add_layout(layout) # Duplicate by copying the settings in a new instance. # - # @return [Lotus::View::Configuration] a copy of the configuration + # @return [Hanami::View::Configuration] a copy of the configuration # # @since 0.2.0 # @api private diff --git a/lib/lotus/view/dsl.rb b/lib/hanami/view/dsl.rb similarity index 78% rename from lib/lotus/view/dsl.rb rename to lib/hanami/view/dsl.rb index 59dd836e..4e43e3b0 100644 --- a/lib/lotus/view/dsl.rb +++ b/lib/hanami/view/dsl.rb @@ -1,7 +1,7 @@ -require 'lotus/view/rendering/template_name' -require 'lotus/view/rendering/layout_finder' +require 'hanami/view/rendering/template_name' +require 'hanami/view/rendering/layout_finder' -module Lotus +module Hanami module View # Class level DSL # @@ -10,7 +10,7 @@ module Dsl # When a value is given, specify a templates root path for the view. # Otherwise, it returns templates root path. # - # When not initialized, it will return the global value from `Lotus::View.root`. + # When not initialized, it will return the global value from `Hanami::View.root`. # # @param value [String] the templates root for this view # @@ -19,28 +19,28 @@ module Dsl # @since 0.1.0 # # @example Default usage - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # end # - # Lotus::View.configuration.root # => 'app/templates' + # Hanami::View.configuration.root # => 'app/templates' # Articles::Show.root # => 'app/templates' # # @example Custom root - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # root 'path/to/articles/templates' # end # end # - # Lotus::View.configuration.root # => 'app/templates' + # Hanami::View.configuration.root # => 'app/templates' # Articles::Show.root # => 'path/to/articles/templates' def root(value = nil) if value.nil? @@ -60,11 +60,11 @@ def root(value = nil) # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # # class JsonShow < Show @@ -83,7 +83,7 @@ def format(value = nil) end # When a value is given, specify the relative path to the template. - # Otherwise, it returns the name that follows Lotus::View conventions. + # Otherwise, it returns the name that follows Hanami::View conventions. # # @param value [String] relative template path # @@ -93,11 +93,11 @@ def format(value = nil) # @since 0.1.0 # # @example Default usage - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # # class JsonShow < Show @@ -109,11 +109,11 @@ def format(value = nil) # Articles::JsonShow.template # => 'articles/show' # # @example Custom template - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # template 'articles/single_article' # end # @@ -126,10 +126,10 @@ def format(value = nil) # Articles::JsonShow.template # => 'articles/single_article' # # @example With namespace - # require 'lotus/view' + # require 'hanami/view' # # module Furnitures - # View = Lotus::View.generate(self) + # View = Hanami::View.generate(self) # # class Standalone # include Furnitures::View @@ -146,10 +146,10 @@ def format(value = nil) # Furnitures::Catalog::Index.template # => 'catalog/index' # # @example With nested namespace - # require 'lotus/view' + # require 'hanami/view' # # module Frontend - # View = Lotus::View.generate(self) + # View = Hanami::View.generate(self) # # class StandaloneView # include Frontend::View @@ -173,11 +173,11 @@ def format(value = nil) # Frontend::Views::Sessions::New.template # => 'sessions/new' # # @example With deeply nested namespace - # require 'lotus/view' + # require 'hanami/view' # # module Bookshelf # module Web - # View = Lotus::View.generate(self) + # View = Hanami::View.generate(self) # # module Views # module Books @@ -189,7 +189,7 @@ def format(value = nil) # end # # module Api - # View = Lotus::View.generate(self) + # View = Hanami::View.generate(self) # # module Views # module Books @@ -212,10 +212,10 @@ def template(value = nil) end # When a value is given, it specifies the layout. - # When false is given, Lotus::View::Rendering::NullLayout is returned. + # When false is given, Hanami::View::Rendering::NullLayout is returned. # Otherwise, it returns the previously specified layout. # - # When the global configuration is set (`Lotus::View.layout=`), after the + # When the global configuration is set (`Hanami::View.layout=`), after the # loading process, it will return that layout if not otherwise specified. # # @param value [Symbol, FalseClass, nil] the layout name @@ -224,29 +224,29 @@ def template(value = nil) # # @since 0.1.0 # - # @see Lotus::Layout + # @see Hanami::Layout # # @example Default usage - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # end # # Articles::Show.layout # => nil # # @example Custom layout - # require 'lotus/view' + # require 'hanami/view' # # class ArticlesLayout - # include Lotus::Layout + # include Hanami::Layout # end # # module Articles # class Show - # include Lotus::View + # include Hanami::View # layout :articles # end # end @@ -254,69 +254,69 @@ def template(value = nil) # Articles::Show.layout # => :articles # # @example Global configuration - # require 'lotus/view' + # require 'hanami/view' # # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # end # - # Lotus::View.layout = :application + # Hanami::View.layout = :application # Articles::Show.layout # => nil # - # Lotus::View.load! + # Hanami::View.load! # Articles::Show.layout # => :application # # @example Global configuration with custom layout - # require 'lotus/view' + # require 'hanami/view' # # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end # # class ArticlesLayout - # include Lotus::Layout + # include Hanami::Layout # end # # module Articles # class Show - # include Lotus::View + # include Hanami::View # layout :articles # end # end # - # Lotus::View.layout = :application + # Hanami::View.layout = :application # Articles::Show.layout # => :articles # - # Lotus::View.load! + # Hanami::View.load! # Articles::Show.layout # => :articles # # @example Disable layout for the view - # require 'lotus/view' + # require 'hanami/view' # # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end # # module Articles # class Show - # include Lotus::View + # include Hanami::View # layout false # end # end # - # Lotus::View.load! - # Articles::Show.layout # => Lotus::View::Rendering::NullLayout + # Hanami::View.load! + # Articles::Show.layout # => Hanami::View::Rendering::NullLayout def layout(value = nil) if value.nil? @_layout ||= Rendering::LayoutFinder.find(@layout || configuration.layout, configuration.namespace) elsif !value - @layout = Lotus::View::Rendering::NullLayout + @layout = Hanami::View::Rendering::NullLayout else @layout = value end @@ -329,7 +329,7 @@ def layout(value = nil) # @api private # @since 0.1.0 # - # @see Lotus::View.load! + # @see Hanami::View.load! def load! super diff --git a/lib/lotus/view/errors.rb b/lib/hanami/view/errors.rb similarity index 84% rename from lib/lotus/view/errors.rb rename to lib/hanami/view/errors.rb index e63cae47..b63ff662 100644 --- a/lib/lotus/view/errors.rb +++ b/lib/hanami/view/errors.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module View # @since 0.5.0 class Error < ::StandardError @@ -6,7 +6,7 @@ class Error < ::StandardError # Missing template error # - # This is raised at the runtime when Lotus::View cannot find a template for + # This is raised at the runtime when Hanami::View cannot find a template for # the requested format. # # We can't raise this error during the loading phase, because at that time @@ -29,13 +29,13 @@ def initialize(template, format) # # @since 0.1.0 # - # @see Lotus::View::Rendering#render + # @see Hanami::View::Rendering#render class MissingFormatError < Error end # Missing template layout error # - # This is raised at the runtime when Lotus::Layout cannot find it's template. + # This is raised at the runtime when Hanami::Layout cannot find it's template. # # @since 0.5.0 class MissingTemplateLayoutError < Error diff --git a/lib/lotus/view/escape.rb b/lib/hanami/view/escape.rb similarity index 81% rename from lib/lotus/view/escape.rb rename to lib/hanami/view/escape.rb index aae23226..b19edf42 100644 --- a/lib/lotus/view/escape.rb +++ b/lib/hanami/view/escape.rb @@ -1,7 +1,7 @@ -require 'lotus/utils/escape' -require 'lotus/presenter' +require 'hanami/utils/escape' +require 'hanami/presenter' -module Lotus +module Hanami module View # Auto escape logic for views and presenters. # @@ -15,19 +15,19 @@ module InstanceMethods # # @param string [String] the input string # - # @return [Lotus::Utils::Escape::SafeString] the string marked as safe + # @return [Hanami::Utils::Escape::SafeString] the string marked as safe # # @since 0.4.0 # @api public # # @example View usage - # require 'lotus/view' + # require 'hanami/view' # # User = Struct.new(:name) # # module Users # class Show - # include Lotus::View + # include Hanami::View # # def user_name # _raw user.name @@ -44,12 +44,12 @@ module InstanceMethods # html # =>
# # @example Presenter usage - # require 'lotus/view' + # require 'hanami/view' # # User = Struct.new(:name) # # class UserPresenter - # include Lotus::Presenter + # include Hanami::Presenter # # def name # _raw @object.name @@ -61,29 +61,29 @@ module InstanceMethods # # presenter.name # => "" def _raw(string) - ::Lotus::Utils::Escape::SafeString.new(string) + ::Hanami::Utils::Escape::SafeString.new(string) end # Force the output escape for the given object # # @param object [Object] the input object # - # @return [Lotus::View::Escape::Presenter] a presenter with output + # @return [Hanami::View::Escape::Presenter] a presenter with output # autoescape # # @since 0.4.0 # @api public # - # @see Lotus::View::Escape::Presenter + # @see Hanami::View::Escape::Presenter # # @example View usage - # require 'lotus/view' + # require 'hanami/view' # # User = Struct.new(:first_name, :last_name) # # module Users # class Show - # include Lotus::View + # include Hanami::View # # def user # _escape locals[:user] @@ -115,7 +115,7 @@ def _raw(string) # # <script>alert('last_name')</script> # # def _escape(object) - ::Lotus::View::Escape::Presenter.new(object) + ::Hanami::View::Escape::Presenter.new(object) end end @@ -124,9 +124,9 @@ def _escape(object) # @since 0.4.0 # @api private # - # @see Lotus::View::Escape::InstanceMethods#_escape + # @see Hanami::View::Escape::InstanceMethods#_escape class Presenter - include ::Lotus::Presenter + include ::Hanami::Presenter end # Escape the given input if it's a string, otherwise return the oject as it is. @@ -152,8 +152,8 @@ def self.html(input) # @api private def self.extended(base) base.class_eval do - include ::Lotus::Utils::ClassAttribute - include ::Lotus::View::Escape::InstanceMethods + include ::Hanami::Utils::ClassAttribute + include ::Hanami::View::Escape::InstanceMethods class_attribute :autoescape_methods self.autoescape_methods = {} @@ -168,7 +168,7 @@ def method_added(method_name) unless autoescape_methods[method_name] prepend Module.new { module_eval %{ - def #{ method_name }(*args, &blk); ::Lotus::View::Escape.html super; end + def #{ method_name }(*args, &blk); ::Hanami::View::Escape.html super; end } } diff --git a/lib/lotus/view/inheritable.rb b/lib/hanami/view/inheritable.rb similarity index 88% rename from lib/lotus/view/inheritable.rb rename to lib/hanami/view/inheritable.rb index e5ba1e9d..553624e1 100644 --- a/lib/lotus/view/inheritable.rb +++ b/lib/hanami/view/inheritable.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module View # Inheriting mechanisms # @@ -10,10 +10,10 @@ module Inheritable # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # end # # class JsonIndexView < IndexView @@ -36,7 +36,7 @@ def subclasses # @api private # @since 0.1.0 # - # @see Lotus::View.load! + # @see Hanami::View.load! def load! subclasses.freeze views.freeze diff --git a/lib/lotus/view/rendering.rb b/lib/hanami/view/rendering.rb similarity index 70% rename from lib/lotus/view/rendering.rb rename to lib/hanami/view/rendering.rb index 5792c2cb..ed800e35 100644 --- a/lib/lotus/view/rendering.rb +++ b/lib/hanami/view/rendering.rb @@ -1,13 +1,13 @@ -require 'lotus/view/rendering/registry' -require 'lotus/view/rendering/scope' +require 'hanami/view/rendering/registry' +require 'hanami/view/rendering/scope' -module Lotus +module Hanami module View # Rendering methods # # @since 0.1.0 # - # @see Lotus::View::Rendering::InstanceMethods + # @see Hanami::View::Rendering::InstanceMethods module Rendering def self.extended(base) base.class_eval do @@ -18,22 +18,22 @@ def self.extended(base) module InstanceMethods # Initialize a view # - # @param template [Lotus::View::Template] the template to render + # @param template [Hanami::View::Template] the template to render # @param locals [Hash] a set of objects available during the rendering # process. # # @since 0.1.0 # - # @see Lotus::View::Template + # @see Hanami::View::Template # # @example - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # end # - # template = Lotus::View::Template.new('index.html.erb') + # template = Hanami::View::Template.new('index.html.erb') # view = IndexView.new(template, {article: article}) def initialize(template, locals) @template = template @@ -51,46 +51,46 @@ def initialize(template, locals) # # @return [String] the output of the rendering process # - # @raise [Lotus::View::MissingTemplateError] if the template is nil + # @raise [Hanami::View::MissingTemplateError] if the template is nil # # @since 0.1.0 # - # @see Lotus::View::Layout + # @see Hanami::View::Layout # # @example with template - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # end # - # template = Lotus::View::Template.new('index.html.erb') + # template = Hanami::View::Template.new('index.html.erb') # view = IndexView.new(template, {article: article}) # - # view.render # =>

Introducing Lotus::view

... + # view.render # =>

Introducing Hanami::view

... # # @example with template and layout - # require 'lotus/view' + # require 'hanami/view' # # class ApplicationLayout - # include Lotus::View::Layout + # include Hanami::View::Layout # end # # class IndexView - # include Lotus::View + # include Hanami::View # layout :application # end # - # template = Lotus::View::Template.new('index.html.erb') + # template = Hanami::View::Template.new('index.html.erb') # view = IndexView.new(template, {article: article}) # - # view.render # => ...

Introducing Lotus::view

... + # view.render # => ...

Introducing Hanami::view

... # # @example with custom rendering - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # # def render # ArticleSerializer.new(article).render @@ -109,7 +109,7 @@ def render # # @return [String] the rendering output # - # @raise [Lotus::View::MissingTemplateError] if the template is nil + # @raise [Hanami::View::MissingTemplateError] if the template is nil # # @api private # @since 0.1.0 @@ -119,11 +119,11 @@ def rendered # The layout. # - # @return [Class, Lotus::View::Rendering::NullLayout] + # @return [Class, Hanami::View::Rendering::NullLayout] # - # @see Lotus::View::Layout - # @see Lotus::View.layout - # @see Lotus::View::Dsl#layout + # @see Hanami::View::Layout + # @see Hanami::View.layout + # @see Hanami::View::Dsl#layout # # @api private # @since 0.1.0 @@ -133,9 +133,9 @@ def layout # The template. # - # @return [Lotus::View::Template] the template + # @return [Hanami::View::Template] the template # - # @raise [Lotus::View::MissingTemplateError] if the template is nil + # @raise [Hanami::View::MissingTemplateError] if the template is nil # # @api private # @since 0.1.0 @@ -147,7 +147,7 @@ def template # # @return [Hash] # - # @see Lotus::View#initialize + # @see Hanami::View#initialize # # @api private # @since 0.1.0 @@ -157,19 +157,19 @@ def locals # Delegates missing methods to the scope. # - # @see Lotus::View::Rendering::Scope + # @see Hanami::View::Rendering::Scope # # @api private # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # class IndexView - # include Lotus::View + # include Hanami::View # end # - # template = Lotus::View::Template.new('index.html.erb') + # template = Hanami::View::Template.new('index.html.erb') # view = IndexView.new(template, {article: article}) # # view.article # => # @@ -187,25 +187,25 @@ def method_missing(m) # # @return [String] the output of the rendering process # - # @raise [Lotus::View::MissingTemplateError] if it can't find a template + # @raise [Hanami::View::MissingTemplateError] if it can't find a template # for the given context # - # @raise [Lotus::View::MissingFormatError] if the given context doesn't + # @raise [Hanami::View::MissingFormatError] if the given context doesn't # have the :format key # # @since 0.1.0 # - # @see Lotus::View#initialize - # @see Lotus::View#render + # @see Hanami::View#initialize + # @see Hanami::View#render # # @example - # require 'lotus/view' + # require 'hanami/view' # # article = OpenStruct.new(title: 'Hello') # # module Articles # class Show - # include Lotus::View + # include Hanami::View # # def title # @title ||= article.title.upcase @@ -221,8 +221,8 @@ def method_missing(m) # end # end # - # Lotus::View.root = '/path/to/templates' - # Lotus::View.load! + # Hanami::View.root = '/path/to/templates' + # Hanami::View.load! # # Articles::Show.render(format: :html, article: article) # # => renders `articles/show.html.erb` @@ -231,7 +231,7 @@ def method_missing(m) # # => renders `articles/show.json.erb` # # Articles::Show.render(format: :xml, article: article) - # # => raises Lotus::View::MissingTemplateError + # # => raises Hanami::View::MissingTemplateError def render(context) registry.resolve(context).render end @@ -243,7 +243,7 @@ def render(context) # @api private # @since 0.1.0 # - # @see Lotus::View.load! + # @see Hanami::View.load! def load! super registry.freeze @@ -256,7 +256,7 @@ def load! # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::Registry + # @see Hanami::View::Rendering::Registry def registry @registry ||= Registry.new(self) end diff --git a/lib/lotus/view/rendering/layout_finder.rb b/lib/hanami/view/rendering/layout_finder.rb similarity index 57% rename from lib/lotus/view/rendering/layout_finder.rb rename to lib/hanami/view/rendering/layout_finder.rb index 41948963..2de0f15b 100644 --- a/lib/lotus/view/rendering/layout_finder.rb +++ b/lib/hanami/view/rendering/layout_finder.rb @@ -1,8 +1,8 @@ -require 'lotus/utils/string' -require 'lotus/utils/class' -require 'lotus/view/rendering/null_layout' +require 'hanami/utils/string' +require 'hanami/utils/class' +require 'hanami/view/rendering/null_layout' -module Lotus +module Hanami module View module Rendering # Defines the logic to find a layout @@ -10,7 +10,7 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::Layout + # @see Hanami::Layout class LayoutFinder # Layout class name suffix # @@ -21,50 +21,50 @@ class LayoutFinder # Find a layout from the given name. # # @param layout [Symbol,String,NilClass] layout name or nil if you want - # to fallback to the framework defaults (see `Lotus::View.layout`). + # to fallback to the framework defaults (see `Hanami::View.layout`). # # @param namespace [Class,Module] a Ruby namespace where to lookup # - # @return [Lotus::Layout] the layout for the given name or - # `Lotus::View.layout` + # @return [Hanami::Layout] the layout for the given name or + # `Hanami::View.layout` # # @api private # @since 0.1.0 # # @example With given name - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View::Rendering::LayoutFinder.find(:article) # => + # Hanami::View::Rendering::LayoutFinder.find(:article) # => # ArticleLayout # # @example With a class - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View::Rendering::LayoutFinder.find(ArticleLayout) # => + # Hanami::View::Rendering::LayoutFinder.find(ArticleLayout) # => # ArticleLayout # # @example With namespace - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View::Rendering::LayoutFinder.find(:application, CardDeck) # => + # Hanami::View::Rendering::LayoutFinder.find(:application, CardDeck) # => # CardDeck::ApplicationLayout # # @example With nil - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View::Rendering::LayoutFinder.find(nil) # => - # Lotus::View::Rendering::NullLayout + # Hanami::View::Rendering::LayoutFinder.find(nil) # => + # Hanami::View::Rendering::NullLayout # # @example With unknown layout - # require 'lotus/view' + # require 'hanami/view' # - # Lotus::View::Rendering::LayoutFinder.find(:unknown) # => - # Lotus::View::Rendering::NullLayout + # Hanami::View::Rendering::LayoutFinder.find(:unknown) # => + # Hanami::View::Rendering::NullLayout # def self.find(layout, namespace = Object) case layout when Symbol, String - # TODO Move this low level logic into a Lotus::Utils solution + # TODO Move this low level logic into a Hanami::Utils solution class_name = "#{ Utils::String.new(layout).classify }#{ SUFFIX }" namespace = Utils::Class.load_from_pattern!(namespace) namespace.const_get(class_name) @@ -85,39 +85,39 @@ def initialize(view) # Find the layout for the view # - # @return [Lotus::Layout] the layout associated to the view + # @return [Hanami::Layout] the layout associated to the view # - # @see Lotus::View::Rendering::LayoutFinder.find - # @see Lotus::View::Rendering::LayoutFinder#initialize + # @see Hanami::View::Rendering::LayoutFinder.find + # @see Hanami::View::Rendering::LayoutFinder#initialize # # @api private # @since 0.1.0 # # @example With layout - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # layout :article # end # end # - # Lotus::View::Rendering::LayoutFinder.new(Articles::Show) # => + # Hanami::View::Rendering::LayoutFinder.new(Articles::Show) # => # ArticleLayout # # @example Without layout - # require 'lotus/view' + # require 'hanami/view' # # module Dashboard # class Index - # include Lotus::View + # include Hanami::View # end # end # - # Lotus::View.layout # => :application + # Hanami::View.layout # => :application # - # Lotus::View::Rendering::LayoutFinder.new(Dashboard::Index) # => + # Hanami::View::Rendering::LayoutFinder.new(Dashboard::Index) # => # ApplicationLayout def find self.class.find(@view.layout) diff --git a/lib/lotus/view/rendering/layout_registry.rb b/lib/hanami/view/rendering/layout_registry.rb similarity index 82% rename from lib/lotus/view/rendering/layout_registry.rb rename to lib/hanami/view/rendering/layout_registry.rb index 1471fc9a..fad11a1d 100644 --- a/lib/lotus/view/rendering/layout_registry.rb +++ b/lib/hanami/view/rendering/layout_registry.rb @@ -1,7 +1,7 @@ -require 'lotus/view/rendering/null_template' -require 'lotus/view/rendering/templates_finder' +require 'hanami/view/rendering/null_template' +require 'hanami/view/rendering/templates_finder' -module Lotus +module Hanami module View module Rendering # Holds the references of all the registered layouts. @@ -10,7 +10,7 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::Layout::ClassMethods#registry + # @see Hanami::Layout::ClassMethods#registry class LayoutRegistry # Initialize the registry # @@ -29,11 +29,11 @@ def initialize(view) # @param context [Hash] the rendering context # @option context [Symbol] :format the requested format # - # @return [Lotus::Layout, Lotus::View::Rendering::NullTemplate] + # @return [Hanami::Layout, Hanami::View::Rendering::NullTemplate] # the layout associated with the given context or a `NullTemplate` if # it can't be found. # - # @raise [Lotus::View::MissingFormatError] if the given context doesn't + # @raise [Hanami::View::MissingFormatError] if the given context doesn't # have the :format key # # @api private diff --git a/lib/lotus/view/rendering/layout_scope.rb b/lib/hanami/view/rendering/layout_scope.rb similarity index 93% rename from lib/lotus/view/rendering/layout_scope.rb rename to lib/hanami/view/rendering/layout_scope.rb index 981582c2..b84a52d2 100644 --- a/lib/lotus/view/rendering/layout_scope.rb +++ b/lib/hanami/view/rendering/layout_scope.rb @@ -1,6 +1,6 @@ -require 'lotus/utils/escape' +require 'hanami/utils/escape' -module Lotus +module Hanami module View module Rendering # Scope for layout rendering @@ -9,8 +9,8 @@ module Rendering class LayoutScope < BasicObject # Initialize the scope # - # @param layout [Lotus::Layout] the layout to render - # @param scope [Lotus::View::Rendering::Scope] the scope of the current + # @param layout [Hanami::Layout] the layout to render + # @param scope [Hanami::View::Rendering::Scope] the scope of the current # view # # @api private @@ -97,7 +97,7 @@ def format # The current view. # - # @return [Lotus::View] the current view + # @return [Hanami::View] the current view # # @since 0.1.0 def view @@ -145,11 +145,11 @@ def locals # # module Products # class Index - # include Lotus::View + # include Hanami::View # end # # class Show - # include Lotus::View + # include Hanami::View # # def footer # "contents for footer" @@ -190,8 +190,8 @@ def respond_to_missing?(m, include_all) # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::Scope - # @see Lotus::Layout + # @see Hanami::View::Rendering::Scope + # @see Hanami::Layout # # @example # # In the layout template: @@ -208,7 +208,7 @@ def method_missing(m, *args, &blk) elsif layout.respond_to?(m) layout.__send__(m, *args, &blk) else - ::Lotus::View::Escape.html(super) + ::Hanami::View::Escape.html(super) end end diff --git a/lib/lotus/view/rendering/null_layout.rb b/lib/hanami/view/rendering/null_layout.rb similarity index 73% rename from lib/lotus/view/rendering/null_layout.rb rename to lib/hanami/view/rendering/null_layout.rb index 2f854496..0c91592f 100644 --- a/lib/lotus/view/rendering/null_layout.rb +++ b/lib/hanami/view/rendering/null_layout.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module View module Rendering # Null Object pattern for Layout. @@ -8,11 +8,11 @@ module Rendering # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # layout false # end # end @@ -22,14 +22,14 @@ class NullLayout # Initialize a layout # - # @param scope [Lotus::View::Rendering::Scope] view rendering scope + # @param scope [Hanami::View::Rendering::Scope] view rendering scope # @param rendered [String] the output of the view rendering process # # @api private # @since 0.1.0 # - # @see Lotus::Layout#initialize - # @see Lotus::View::Rendering#render + # @see Hanami::Layout#initialize + # @see Hanami::View::Rendering#render def initialize(scope, rendered) @rendered = rendered end @@ -41,8 +41,8 @@ def initialize(scope, rendered) # @api private # @since 0.1.0 # - # @see Lotus::Layout#render - # @see Lotus::View::Rendering#render + # @see Hanami::Layout#render + # @see Hanami::View::Rendering#render def render @rendered end diff --git a/lib/lotus/view/rendering/null_template.rb b/lib/hanami/view/rendering/null_template.rb similarity index 87% rename from lib/lotus/view/rendering/null_template.rb rename to lib/hanami/view/rendering/null_template.rb index 19192a6c..5c2c22d6 100644 --- a/lib/lotus/view/rendering/null_template.rb +++ b/lib/hanami/view/rendering/null_template.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module View module Rendering # Null Object pattern for layout template @@ -15,18 +15,18 @@ module Rendering # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # # # We have an ApplicationLayout (views/application_layout.rb): # class ApplicationLayout - # include Lotus::Layout + # include Hanami::Layout # end # # # Our layout has a template for HTML requests, located at: # # templates/application.html.erb # # # We set it as global layout - # Lotus::View.layout = :application + # Hanami::View.layout = :application # # # We have two views for HTML and JSON articles. # # They have a template each: @@ -35,7 +35,7 @@ module Rendering # # * templates/articles/show.json.erb # module Articles # class Show - # include Lotus::View + # include Hanami::View # format :html # end # @@ -45,7 +45,7 @@ module Rendering # end # # # We initialize the framework - # Lotus::View.load! + # Hanami::View.load! # # # @@ -63,7 +63,7 @@ module Rendering class NullTemplate # Render the layout template # - # @param scope [Lotus::View::Scope] the rendering scope + # @param scope [Hanami::View::Scope] the rendering scope # @param locals [Hash] a set of objects available during the rendering # @yield [Proc] yields the given block # @@ -72,8 +72,8 @@ class NullTemplate # @api private # @since 0.1.0 # - # @see Lotus::Layout#render - # @see Lotus::View::Rendering#render + # @see Hanami::Layout#render + # @see Hanami::View::Rendering#render def render(scope, locals = {}) yield end diff --git a/lib/lotus/view/rendering/partial.rb b/lib/hanami/view/rendering/partial.rb similarity index 77% rename from lib/lotus/view/rendering/partial.rb rename to lib/hanami/view/rendering/partial.rb index 9c7893d8..301f8d66 100644 --- a/lib/lotus/view/rendering/partial.rb +++ b/lib/hanami/view/rendering/partial.rb @@ -1,6 +1,6 @@ -require 'lotus/view/rendering/partial_finder' +require 'hanami/view/rendering/partial_finder' -module Lotus +module Hanami module View module Rendering # Rendering partial @@ -10,8 +10,8 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::Template - # @see Lotus::View::Rendering::LayoutScope#render + # @see Hanami::View::Rendering::Template + # @see Hanami::View::Rendering::LayoutScope#render # # @example # # We have an application template (templates/application.html.erb) diff --git a/lib/lotus/view/rendering/partial_finder.rb b/lib/hanami/view/rendering/partial_finder.rb similarity index 85% rename from lib/lotus/view/rendering/partial_finder.rb rename to lib/hanami/view/rendering/partial_finder.rb index e22bd67a..06a8750d 100644 --- a/lib/lotus/view/rendering/partial_finder.rb +++ b/lib/hanami/view/rendering/partial_finder.rb @@ -1,13 +1,13 @@ -require 'lotus/view/rendering/template_finder' +require 'hanami/view/rendering/template_finder' -module Lotus +module Hanami module View module Rendering # Find a partial for the current view context. # It's used when a template wants to render a partial. # - # @see Lotus::View::Rendering::Partial - # @see Lotus::View::Rendering::TemplateFinder + # @see Hanami::View::Rendering::Partial + # @see Hanami::View::Rendering::TemplateFinder # # @api private # @since 0.1.0 @@ -27,9 +27,9 @@ class PartialFinder < TemplateFinder # view template, if not found it will search recursivly from # the view root. # - # @return [Lotus::View::Template] the requested template + # @return [Hanami::View::Template] the requested template # - # @see Lotus::View::Rendering::TemplateFinder#find + # @see Hanami::View::Rendering::TemplateFinder#find # # @since 0.4.3 # @api private diff --git a/lib/lotus/view/rendering/registry.rb b/lib/hanami/view/rendering/registry.rb similarity index 73% rename from lib/lotus/view/rendering/registry.rb rename to lib/hanami/view/rendering/registry.rb index 38acf322..f606f9a6 100644 --- a/lib/lotus/view/rendering/registry.rb +++ b/lib/hanami/view/rendering/registry.rb @@ -1,7 +1,7 @@ -require 'lotus/view/rendering/layout_registry' -require 'lotus/view/rendering/view_finder' +require 'hanami/view/rendering/layout_registry' +require 'hanami/view/rendering/view_finder' -module Lotus +module Hanami module View module Rendering # Holds all the references of all the registered subclasses of a view. @@ -10,19 +10,19 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::LayoutRegistry - # @see Lotus::View::Rendering#registry + # @see Hanami::View::Rendering::LayoutRegistry + # @see Hanami::View::Rendering#registry # # @example - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Index - # include Lotus::View + # include Hanami::View # end # # class Show - # include Lotus::View + # include Hanami::View # end # # class JsonShow < Show @@ -57,13 +57,13 @@ module Rendering # # It holds the references for all the templates and the views # Articles::Index.send(:registry).inspect # # => { :all => [Articles::Index, nil], - # # :atom => [Articles::Index, # [Articles::Index, # [Articles::Index, # [Articles::Index, # { :all => [Articles::Show, nil], - # # :html => [Articles::Show, # [Articles::JsonShow, # [Articles::Show, # [Articles::JsonShow, # [Articles::XmlShow, nil] } class Registry < LayoutRegistry # Default format for views without an explicit format. @@ -71,7 +71,7 @@ class Registry < LayoutRegistry # @api private # @since 0.1.0 # - # @see Lotus::View::Dsl#format + # @see Hanami::View::Dsl#format DEFAULT_FORMAT = :all # Returns the view for the given context. @@ -79,15 +79,15 @@ class Registry < LayoutRegistry # @param context [Hash] the rendering context # @option context [Symbol] :format the requested format # - # @return [Lotus::View] the view associated with the given context + # @return [Hanami::View] the view associated with the given context # - # @raise [Lotus::View::MissingFormatError] if the given context doesn't + # @raise [Hanami::View::MissingFormatError] if the given context doesn't # have the :format key # # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering#render + # @see Hanami::View::Rendering#render def resolve(context) view, template = @registry.fetch(format(context)) { @registry[DEFAULT_FORMAT] } view.new(template, context) diff --git a/lib/lotus/view/rendering/scope.rb b/lib/hanami/view/rendering/scope.rb similarity index 88% rename from lib/lotus/view/rendering/scope.rb rename to lib/hanami/view/rendering/scope.rb index 64ce0032..9cb79562 100644 --- a/lib/lotus/view/rendering/scope.rb +++ b/lib/hanami/view/rendering/scope.rb @@ -1,16 +1,16 @@ -require 'lotus/utils/escape' -require 'lotus/view/rendering/layout_scope' -require 'lotus/view/rendering/template' -require 'lotus/view/rendering/partial' +require 'hanami/utils/escape' +require 'hanami/view/rendering/layout_scope' +require 'hanami/view/rendering/template' +require 'hanami/view/rendering/partial' -module Lotus +module Hanami module View module Rendering # Rendering scope # # @since 0.1.0 # - # @see Lotus::View::Rendering::LayoutScope + # @see Hanami::View::Rendering::LayoutScope class Scope < LayoutScope # Initialize the scope # @@ -60,7 +60,7 @@ def respond_to_missing?(m, include_all) protected def method_missing(m, *args, &block) - ::Lotus::View::Escape.html( + ::Hanami::View::Escape.html( if @view.respond_to?(m) @view.__send__ m, *args, &block elsif @locals.key?(m) diff --git a/lib/lotus/view/rendering/template.rb b/lib/hanami/view/rendering/template.rb similarity index 86% rename from lib/lotus/view/rendering/template.rb rename to lib/hanami/view/rendering/template.rb index 4a6b2304..f8c8ac6d 100644 --- a/lib/lotus/view/rendering/template.rb +++ b/lib/hanami/view/rendering/template.rb @@ -1,6 +1,6 @@ -require 'lotus/view/rendering/template_finder' +require 'hanami/view/rendering/template_finder' -module Lotus +module Hanami module View module Rendering # Rendering template @@ -10,7 +10,7 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::LayoutScope#render + # @see Hanami::View::Rendering::LayoutScope#render # # @example # # We have an application template (templates/application.html.erb) @@ -20,7 +20,7 @@ module Rendering class Template # Initialize a template # - # @param view [Lotus::View] the current view + # @param view [Hanami::View] the current view # @param options [Hash] the rendering informations # @option options [Symbol] :format the current format # @option options [Hash] :locals the set of objects available within @@ -36,7 +36,7 @@ def initialize(view, options) # # @return [String] the output of the rendering process. # - # @raise [Lotus::View::MissingTemplateError] if template can't be found + # @raise [Hanami::View::MissingTemplateError] if template can't be found # # @api private # @since 0.1.0 diff --git a/lib/lotus/view/rendering/template_finder.rb b/lib/hanami/view/rendering/template_finder.rb similarity index 75% rename from lib/lotus/view/rendering/template_finder.rb rename to lib/hanami/view/rendering/template_finder.rb index 2eeef428..3fdf7058 100644 --- a/lib/lotus/view/rendering/template_finder.rb +++ b/lib/hanami/view/rendering/template_finder.rb @@ -1,13 +1,13 @@ -require 'lotus/view/rendering/templates_finder' +require 'hanami/view/rendering/templates_finder' -module Lotus +module Hanami module View module Rendering # Find a template for the current view context. # It's used when a template wants to render another template. # - # @see Lotus::View::Rendering::Template - # @see Lotus::View::Rendering::TemplatesFinder + # @see Hanami::View::Rendering::Template + # @see Hanami::View::Rendering::TemplatesFinder # # @api private # @since 0.1.0 @@ -28,13 +28,13 @@ def initialize(view, options) # Find a template for the current view context # - # @return [Lotus::View::Template] the requested template + # @return [Hanami::View::Template] the requested template # # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::TemplatesFinder#find - # @see Lotus::View::Rendering::Template#render + # @see Hanami::View::Rendering::TemplatesFinder#find + # @see Hanami::View::Rendering::Template#render def find super.first end diff --git a/lib/lotus/view/rendering/template_name.rb b/lib/hanami/view/rendering/template_name.rb similarity index 94% rename from lib/lotus/view/rendering/template_name.rb rename to lib/hanami/view/rendering/template_name.rb index ef6f5675..c098489a 100644 --- a/lib/lotus/view/rendering/template_name.rb +++ b/lib/hanami/view/rendering/template_name.rb @@ -1,6 +1,6 @@ -require 'lotus/utils/string' +require 'hanami/utils/string' -module Lotus +module Hanami module View module Rendering # @since 0.2.0 diff --git a/lib/lotus/view/rendering/templates_finder.rb b/lib/hanami/view/rendering/templates_finder.rb similarity index 84% rename from lib/lotus/view/rendering/templates_finder.rb rename to lib/hanami/view/rendering/templates_finder.rb index 75f42ab6..ee3ab891 100644 --- a/lib/lotus/view/rendering/templates_finder.rb +++ b/lib/hanami/view/rendering/templates_finder.rb @@ -1,6 +1,6 @@ -require 'lotus/view/template' +require 'hanami/view/template' -module Lotus +module Hanami module View module Rendering # Find templates for a view @@ -42,20 +42,20 @@ def initialize(view) # It recursively looks for templates under the root path of the view, # that are matching the template name # - # @return [Array] the templates + # @return [Array] the templates # # @api private # @since 0.1.0 # - # @see Lotus::View::Dsl#root - # @see Lotus::View::Dsl#template + # @see Hanami::View::Dsl#root + # @see Hanami::View::Dsl#template # # @example - # require 'lotus/view' + # require 'hanami/view' # # module Articles # class Show - # include Lotus::View + # include Hanami::View # end # end # @@ -66,8 +66,8 @@ def initialize(view) # # # # "/path/to/templates/articles/show.html.erb" # - # Lotus::View::Rendering::TemplatesFinder.new(Articles::Show).find - # # => [#] + # Hanami::View::Rendering::TemplatesFinder.new(Articles::Show).find + # # => [#] def find _find.map do |template| View::Template.new(template, @view.configuration.default_encoding) diff --git a/lib/lotus/view/rendering/view_finder.rb b/lib/hanami/view/rendering/view_finder.rb similarity index 84% rename from lib/lotus/view/rendering/view_finder.rb rename to lib/hanami/view/rendering/view_finder.rb index c6725eca..f39e48f5 100644 --- a/lib/lotus/view/rendering/view_finder.rb +++ b/lib/hanami/view/rendering/view_finder.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module View module Rendering # Find a view @@ -6,7 +6,7 @@ module Rendering # @api private # @since 0.1.0 # - # @see Lotus::View::Rendering::Registry + # @see Hanami::View::Rendering::Registry class ViewFinder # Initialize a finder # @@ -21,7 +21,7 @@ def initialize(view) # Find a view for the given template. # It looks up for the current view and its subclasses. # - # @param template [Lotus::View::Template] a template to be associated + # @param template [Hanami::View::Template] a template to be associated # to a view # # @return [Class] a view associated with the given template diff --git a/lib/lotus/view/template.rb b/lib/hanami/view/template.rb similarity index 80% rename from lib/lotus/view/template.rb rename to lib/hanami/view/template.rb index a4016f4f..bb7516cd 100644 --- a/lib/lotus/view/template.rb +++ b/lib/hanami/view/template.rb @@ -1,6 +1,6 @@ require 'tilt' -module Lotus +module Hanami module View # A logic-less template. # @@ -17,9 +17,9 @@ def initialize(template, encoding = Encoding::UTF_8) # @since 0.1.0 # # @example - # require 'lotus/view' + # require 'hanami/view' # - # template = Lotus::View::Template.new('index.html.erb') + # template = Hanami::View::Template.new('index.html.erb') # template.format # => :html def format @_template.basename.match(/\.([^.]+)/).captures.first.to_sym @@ -27,14 +27,14 @@ def format # Render the template within the context of the given scope. # - # @param scope [Lotus::View::Scope] the rendering scope + # @param scope [Hanami::View::Scope] the rendering scope # # @return [String] the output of the rendering process # # @api private # @since 0.1.0 # - # @see Lotus::View::Scope + # @see Hanami::View::Scope def render(scope, &blk) @_template.render(scope, {}, &blk) end diff --git a/lib/lotus/view/version.rb b/lib/hanami/view/version.rb similarity index 63% rename from lib/lotus/view/version.rb rename to lib/hanami/view/version.rb index 4c13fff3..0cd78906 100644 --- a/lib/lotus/view/version.rb +++ b/lib/hanami/view/version.rb @@ -1,8 +1,8 @@ -module Lotus +module Hanami module View # Defines the version # # @since 0.1.0 - VERSION = '0.5.0'.freeze + VERSION = '0.6.0'.freeze end end diff --git a/lib/lotus-view.rb b/lib/lotus-view.rb deleted file mode 100644 index 816bc3a9..00000000 --- a/lib/lotus-view.rb +++ /dev/null @@ -1 +0,0 @@ -require 'lotus/view' diff --git a/test/escape_test.rb b/test/escape_test.rb index 18cfeff0..d3e10b68 100644 --- a/test/escape_test.rb +++ b/test/escape_test.rb @@ -3,7 +3,7 @@ describe 'Escape' do before do path = Pathname.new(__dir__ + '/fixtures/templates/users/show.html.erb') - template = Lotus::View::Template.new(path, 'utf-8') + template = Hanami::View::Template.new(path, 'utf-8') @user = User.new(%()) @book = Book.new(%()) diff --git a/test/fixtures.rb b/test/fixtures.rb index 4218dca9..a99b17dd 100644 --- a/test/fixtures.rb +++ b/test/fixtures.rb @@ -1,20 +1,20 @@ require 'json' class HelloWorldView - include Lotus::View + include Hanami::View end class DisabledLayoutView - include Lotus::View + include Hanami::View layout false end class RenderView - include Lotus::View + include Hanami::View end class RenderViewMethodOverride - include Lotus::View + include Hanami::View def select 'foo' @@ -22,7 +22,7 @@ def select end class RenderViewMethodWithArgs - include Lotus::View + include Hanami::View def planet(name) name.to_s @@ -30,7 +30,7 @@ def planet(name) end class RenderViewMethodWithBlock - include Lotus::View + include Hanami::View def each_thing yield 'thing 1' @@ -40,20 +40,20 @@ def each_thing end class RenderViewWithMissingPartialTemplate - include Lotus::View + include Hanami::View end class EncodingView - include Lotus::View + include Hanami::View end class JsonRenderView - include Lotus::View + include Hanami::View format :json end class AppView - include Lotus::View + include Hanami::View root __dir__ + '/fixtures/templates/app' layout :application end @@ -67,37 +67,37 @@ class AppViewRoot < AppView end class NestedView - include Lotus::View + include Hanami::View root __dir__ + '/fixtures/templates' end module Organisations class Action - include Lotus::View + include Hanami::View root __dir__ + '/fixtures/templates' end module OrderTemplates class Action - include Lotus::View + include Hanami::View root __dir__ + '/fixtures/templates' end end end class MissingTemplateView - include Lotus::View + include Hanami::View end module App class View - include Lotus::View + include Hanami::View end end class ApplicationLayout - include Lotus::Layout + include Hanami::Layout def title 'Title:' @@ -109,7 +109,7 @@ class GlobalLayout module Articles class Index - include Lotus::View + include Hanami::View layout :application def title @@ -128,7 +128,7 @@ class AtomIndex < RssIndex end class New - include Lotus::View + include Hanami::View def errors {} @@ -136,7 +136,7 @@ def errors end class Create - include Lotus::View + include Hanami::View template 'articles/new' def errors @@ -145,7 +145,7 @@ def errors end class Show - include Lotus::View + include Hanami::View def title @title ||= article.title.upcase @@ -182,7 +182,7 @@ def names end class MapPresenter - include Lotus::Presenter + include Hanami::Presenter def count locations.count @@ -207,7 +207,7 @@ def inspect_object module Dashboard class Index - include Lotus::View + include Hanami::View def map MapPresenter.new(locals[:map]) @@ -216,7 +216,7 @@ def map end class IndexView - include Lotus::View + include Hanami::View layout :application end @@ -235,7 +235,7 @@ def render module Songs class Show - include Lotus::View + include Hanami::View format :html def render @@ -246,7 +246,7 @@ def render module Metrics class Index - include Lotus::View + include Hanami::View def render %(metrics) @@ -256,13 +256,13 @@ def render module Contacts class Show - include Lotus::View + include Hanami::View end end module Nodes class Parent - include Lotus::View + include Hanami::View end end @@ -273,7 +273,7 @@ module MyOtherCustomModule end module CardDeck - View = Lotus::View.duplicate(self) do + View = Hanami::View.duplicate(self) do namespace CardDeck root __dir__ + '/fixtures/templates/card_deck/app/templates' layout :application @@ -345,13 +345,13 @@ def raise_error end module Store - View = Lotus::View.duplicate(self) + View = Hanami::View.duplicate(self) View.extend Unloadable module Helpers module AssetTagHelpers def javascript_tag(source) - Lotus::Utils::Escape::SafeString.new %(