Rails: Is it possible to write view helpers with HAML syntax?

后端 未结 4 1203
萌比男神i
萌比男神i 2021-02-12 19:05

During refactoring it would be quite handy just to copy part of HAML template and paste it to helper\'s code. Currently in such cases 1) I have to rewrite that part of view from

4条回答
  •  难免孤独
    2021-02-12 19:53

    Haml now has a capture_haml method that you can use to accomplish this.

      def some_helper
        capture_haml do
          .some_class
            = yield
          #some-code-after
        end
      end
    
    some_helper do
      %h1 Hello World
    end
    => 

    Hello World

    Here is a link with more info on capture_haml: http://haml.info/docs/yardoc/Haml/Helpers.html#capture_haml-instance_method

提交回复
热议问题