How to use Slim directly in ruby -


i create basic ruby script renders slim templates html (this part of larger project). ideally use html produced within script.

i understand possible using tilt (as shown in slim readme) says following:


slim uses tilt compile generated code. if want use slim template directly, can use tilt interface.

 tilt.new['template.slim'].render(scope)  slim::template.new('template.slim', optional_option_hash).render(scope)  slim::template.new(optional_option_hash) { source }.render(scope) 

the optional option hash can have options documented in section above. scope object in template code executed.


however, i'm still unable run this. therefore, wondering if me producing working example.

edit (this has been edited further ):

i have played code quite bit keep on getting following error:

 undefined local variable or method `source' main:object (nameerror) 

this i'm running:

require 'slim'  # i'm not sure next 2 lines... optional_option_hash = {} scope = object.new      tilt.new('template.slim').render(scope) slim::template.new('template.slim', optional_option_hash).render(scope) slim::template.new(optional_option_hash) { source }.render(scope)     

many help.

see specifying layout , template in standalone (not rails) ruby app, using slim or haml

this ended using:

require 'slim'  # simple class represent environment class env   attr_accessor :name end  scope = env.new scope.name = "test layout"  layout =<<eos h1 hello .content   = yield eos  contents =<<eos   = name eos  layout = slim::template.new { layout } content = slim::template.new { contents }.render(scope)  puts layout.render{ content } 

for scope, can put in modules/classes or self.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -