haml

$ is not defined, Uncaught ReferenceError while using Select2 plugin with Rails

不打扰是莪最后的温柔 提交于 2019-12-24 00:27:58
问题 I'm trying to use the Select2 plugin to add a search bar to my select box. I get the following error when looking at the page console : Uncaught ReferenceError: $ is not defined Searching different questions here led me to believe this error happens because the jQuery javascript is not included or put before the script is called. But I still could not find a way to make it work. How can I fix this error and make the select2 plugin work? Here is the application.js file : //= require jquery //=

using the :sass filter with :css

女生的网名这么多〃 提交于 2019-12-23 23:23:11
问题 We are currently making a widget that requires some default declared styles along with it(widget html is included by javasacript, along with the default css in style tags) but the problem is i can't "chain" haml filters. What I'm trying to do is to add an internal stylesheet along with the widget like so: <style type="text/css"> p {color: #f00;} </style> <div id="widget-goes-here"> <p>etc</p> </div> We are using haml so I tried doing it with the sass filter: :sass p :color #f00 #widget-goes

Rails HAML engine rendering

扶醉桌前 提交于 2019-12-23 18:51:55
问题 What is wrong here? Haml::Engine.new('= image_tag("golfer.png")').render image_tag is always undefined (ActionView::Helpers in not loaded). How can I fix that? Thx! 回答1: I think I found the solution. class TagHelper include Singleton include ActionView::Helpers::TagHelper include ActionView::Helpers::AssetTagHelper end puts Haml::Engine.new('= image_tag("golfer.png")').render(TagHelper.instance) 来源: https://stackoverflow.com/questions/4097642/rails-haml-engine-rendering

Possible to embed markdown within erb?

↘锁芯ラ 提交于 2019-12-23 18:11:59
问题 If you use haml as rails view template, you can write portion of your page using markdown by using the ":markdown" filter. Is is possible to do the same using erb? 回答1: ERB does not have filtering like this built-in. You'll need to directly use a gem that handles it, like RDiscount or the venerable BlueCloth. 回答2: It's pretty easy to write a method that does it, assuming you're using something like Rails which has #capture , #concat , and #markdown helpers. Here's an example, using Maruku:

Converting all .haml files in a dir to .html in another dir

試著忘記壹切 提交于 2019-12-23 17:17:04
问题 In a simple website I'm working on, I have a directory haml and a directory pages . The haml folder contains the .haml files I work on, and the pages folder contains my converted .html files. I know I can convert the files, from the website root directory, by doing: haml haml/about.haml pages/about.html for each file. However, is there a way to convert all the .haml files in my haml folder to an equivalent .html file in the pages folder? Something like: haml haml/*.haml html/*.html Thanks!

How to let a line end with | (pipe) in HAML?

不问归期 提交于 2019-12-23 15:05:02
问题 The problem is that a | at the end of a line (seperated by whitespace) is recognized as syntax for advanced line-breaks. What to do if you want to get this character as output? Example Say you want to create a menu like Section 1 | Section 2 | ... Note: if this is just what you want then take a look at concatenate link_to with pipe. Wether or not a link is shown depends on a certain condition. In HAML/Ruby on Rails this could look like which does not work %div.menu -if condition1? #{link_to

Slim templates - removing whitespaces around the block tag

眉间皱痕 提交于 2019-12-23 13:59:41
问题 I'm trying Slim templates in a new project (after using Haml for quite a while). While overall experience is great, I've run into a problem with spaces being always inserted around tags which normally use display: block Say, ul.ampm li.am am li.pm pm generates <ul class="ampm"> <li class="am"> am </li> <li class="pm"> pm </li> </ul> while .ampm span.am am span.pm pm generates <div class="ampm"> <span class="am">am</span></span class="pm">pm</span> </div> Normally it's not a big issue, but we

HAML - a very weird indentation difference - bug?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 13:27:31
问题 This HAML %script{:type => "text/javascript"} :plain $(document).ready(function() { bar(); var foo = foo_func("#{}"); }); as expected gives this: <script type='text/javascript'> $(document).ready(function() { bar(); var foo = foo_func(""); }); </script> But this ALMOST IDENTICAL HAML (changed only bar() to prep() ): %script{:type => "text/javascript"} :plain $(document).ready(function() { prep(); var foo = foo_func("#{}"); }); gives this: <script type='text/javascript'> $(document).ready

How can I do to write “Text” just once and in the same time check if the path_info includes 'A'?

╄→гoц情女王★ 提交于 2019-12-23 11:53:07
问题 - if !request.path_info.include? 'A' %{:id => 'A'} "Text" - else "Text" "Text" is written twice. How can I do to write it just once and in the same time check if the path_info includes 'A'? 回答1: There are two ways to do this. Using a partial , or using a content_for block : If "Text" was longer, or was a significant subtree, you could extract it into a partial. This would DRY up your code a little. In the example given this would seem like overkill. The better way in this case would be to use

ending haml comments

拟墨画扇 提交于 2019-12-23 07:27:41
问题 I am new to haml and this is stumping me. I don't like to delete code where I can comment it out but I have no idea how to properly end a comment in haml. Here is a code snippit: .field = f.label :member_id %br/ = f.text_field :member_id .field = f.label :instrument_type %br/ I'm trying to comment out the first field so I used: / .field = f.label :member_id %br/ = f.text_field :member_id .field = f.label :instrument_type %br/ but that commented out everything after the first field. Then I