Sha256: bcdf04b3d1a4120a56300b8315660f64e2a24b624916cb66a437d96bd25c58e0
Contents?: true
Size: 1.79 KB
Versions: 5
Compression:
Stored size: 1.79 KB
Contents
format do include Card::Set::Format::HamlViews define_method :the_scope do set_scope end define_method :haml_scope do set_scope end # Renders haml templates. The haml template can be passed as string or # block or a symbol that refers to a view template. # @param template_or_locals [Hash, String, Symbol] # If a symbol is given then a template is expected in the corresponding view # directory. # @return [String] rendered haml as HTML # @example render a view template # # view/type/basic/my_template.haml: # %p # Hi # = name # # # set/type/basic.rb: # view :my_view do # haml :my_template, name: "Joe: # => "<p>Hi Joe<p/>" # end # @example use a block to pass haml # haml name: "Joe" do # <<-HAML.strip_heredoc # %p # Hi # = name # HAML # # => <p>Hi Joe</p> # @example create a slot in haml code # - haml_wrap do # %p # some haml def haml *args, &block if args.first.is_a? Symbol process_haml_template(*args) else process_haml(*args, &block) end end def haml_partial partial, locals={} locals[:template_path] ||= @template_path process_haml_template "_#{partial}".to_sym, locals end private def process_haml *args args.unshift yield if block_given? haml_to_html(*args) end def process_haml_template template_name, locals={} path = identify_template_path template_name, locals with_template_path path do haml_to_html ::File.read(path), locals end rescue => e raise Card::Error, "HAML error #{template_name}: #{e.message}" end def identify_template_path view, locals={} base_path = locals.delete(:template_path) || caller_locations[2].path haml_template_path view, base_path end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
card-1.93.8 | mod/core/set/all/haml.rb |
card-1.93.7 | mod/core/set/all/haml.rb |
card-1.93.6 | mod/core/set/all/haml.rb |
card-1.93.5 | mod/core/set/all/haml.rb |
card-1.93.4 | mod/core/set/all/haml.rb |