These are chat archives for Codcore/amethyst

28th
Jul 2015
Giorgio Pellero
@trapped
Jul 28 2015 10:47
hi everyone
I wanted to ask a little question about Amethyst
I'd like to have a middleware that adds html head/etc to the response so that my views do not get bloated
however this does not seem to cut it https://gist.github.com/trapped/127cb61d13ffc29005c5
giving me this (after a series of undefined method/Nil errors): "Error: instance variable '@response' of Headers was not initialized in all of the 'initialize' methods, rendering it nilable"
Bar Hofesh
@bararchy
Jul 28 2015 10:49
@trapped Welcome :) would you mind share the view of header ?
I mean the actual .ecr code
Bar Hofesh
@bararchy
Jul 28 2015 10:53
@trapped well, this seems like a bug, but, for a quick workaround you could try what @jhass saied in the Crystal IRC chan, or , you can also try to put @partial_body = '' under view to initialize it, this way even if you get a nil value in the code it will be initialized
like
class Headers < Middleware::Base
  view "header",    "#{__DIR__}/views"
  @partial_body = ''

  def call(request)
    response = @app.call(request)
    @partial_body = response.body
    response.body = html render "header"
    response
  end
end
@Codcore what do you think ?
Giorgio Pellero
@trapped
Jul 28 2015 10:55
I might be doing something wrong but that still doesn't compile
Bar Hofesh
@bararchy
Jul 28 2015 11:00
@trapped Oh, @partial_body = response.body if response.body
Giorgio Pellero
@trapped
Jul 28 2015 11:01
same error, keeps complaining that response is Nil
I don't think it's not complaining about @partial_body at all, is it
Bar Hofesh
@bararchy
Jul 28 2015 11:01
class Headers < Middleware::Base
  view "header",    "#{__DIR__}/views"
  @partial_body = ''

  def call(request)
    response = @app.call(request)
    @partial_body = response.body if response
    response.body = html render "header" if response
    response
  end
end
Giorgio Pellero
@trapped
Jul 28 2015 11:02
also single quotes for partial_body would make it a char
tried, didn't work, same error
Bar Hofesh
@bararchy
Jul 28 2015 11:03
:/ apperntly a bug then
@Sdogruyol , @Codcore this is up to you guys now
Giorgio Pellero
@trapped
Jul 28 2015 11:51
Bar Hofesh
@bararchy
Jul 28 2015 12:08
@trapped Great :)
Serdar Dogruyol
@sdogruyol
Jul 28 2015 12:21
hey
Bar Hofesh
@bararchy
Jul 28 2015 12:35
@Sdogruyol Hi dude :)
Serdar Dogruyol
@sdogruyol
Jul 28 2015 12:55
@bararchy hey sup