Giter VIP home page Giter VIP logo

Comments (7)

twe4ked avatar twe4ked commented on May 19, 2024

I'll take a crack at this. Might be a few days as I'm in and out of internet.

from hanami.

simi avatar simi commented on May 19, 2024

We can inspire here - https://github.com/hassox/rack-rescue/blob/master/lib/rack/rescue.rb for production and I think we can add https://github.com/charliesome/better_errors into default generated app Gemfile (and make it optionable in generator). I don't see any reason why we should duplicate better_errors code.

from hanami.

jodosha avatar jodosha commented on May 19, 2024

@simi The scope of this ticket is to allow to customize production error pages.

While better_errors is for development purposes. Because Lotus depends on Rack, we already have Rack::ShowExceptions as an alternative.

from hanami.

simi avatar simi commented on May 19, 2024

So plan is to add custom configurable rack middleware to production middleware stack to handle errors?

from hanami.

jodosha avatar jodosha commented on May 19, 2024

@simi Where did you read that? Rack::ShowExceptions is for development as well, and it's out of scope here.

Right now we have the scenario depicted in the description of this ticket.

The idea is to let developers to add a file like apps/bookshelf/templates/500.html.erb, where they can define the production error page.

from hanami.

jodosha avatar jodosha commented on May 19, 2024

Reporting here an idea of for implementation, that I had in a discussion with @twe4ked .

If you look at the signature of a view's constructor it's: #initialize(template, locals). Lotus::View.render is also a factory: it instantiate a view, passing the right template.

What if we override it?

def self.render(root, template_name, context)
  if template = DefaultTemplateFinder.new(root, template_name).find
    new(template, context).render # the developer has defined a custom template
  else
    super(context) # render the default view
  end
end

..and

class Lotus::Views::DefaultTemplateFinder < Lotus::View::Rendering::TemplateFinder
  def initialize(root, template_name)
     @root = root
     @options = { template_name: template_name }
  end

  private
  def root
    @root
  end
end

.. to be used like:

# lib/lotus/rendering_policy.rb
Lotus::Views::Default.render(@templates, response.code, {response: response, format: :html})

from hanami.

twe4ked avatar twe4ked commented on May 19, 2024

I got this working but never had time to finish the tests. I'll try get to it soon but if anyone else gets to it first that's fine. Sorry it's taken so long. I assume we would want integration tests for this? I created a PR (#61) of what I've got so far.

from hanami.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.