emilioforrer / haml_coffee_assets Goto Github PK
View Code? Open in Web Editor NEWHaml Coffee templates in the Rails asset pipeline or as Sprockets engine.
Home Page: https://rubygems.org/gems/haml_coffee_assets
License: MIT License
Haml Coffee templates in the Rails asset pipeline or as Sprockets engine.
Home Page: https://rubygems.org/gems/haml_coffee_assets
License: MIT License
> test1 = '
- for i in [1..5]
%i{:class => "prefix-#{i}"}'
> HamlCoffeeAssets::HamlCoffee.compile 'test1', test1, false
=> "(function(context) {\n return (function() {\n var $o, i;\n $o = [];\n for (i = 1; i <= 5; i++) {\n $o.push(\"<i class='prefix-\" + i + \"'></i>\");\n }\n return $o.join(\"\\n\").replace(/\\s(\\w+)='true'/mg, ' $1').replace(/\\s(\\w+)='false'/mg, '');\n }).call(HAML.context(context));\n});"
> test2 = '
- for i in [1..5]
%i.other{:class => "prefix-#{i}"}'
HamlCoffeeAssets::HamlCoffee.compile 'test2', test2, false
=> "(function(context) {\n return (function() {\n var $o, i;\n $o = [];\n for (i = 1; i <= 5; i++) {\n $o.push(\"<i class='\" + (['other', i].sort().join(' ')) + \"'></i>\");\n }\n return $o.join(\"\\n\").replace(/\\s(\\w+)='true'/mg, ' $1').replace(/\\s(\\w+)='false'/mg, '');\n }).call(HAML.context(context));\n});"
In first case we are getting expected class=("prefix" + i), but in the second case prefix is omitted: class=(['other', i].sort().join(' '))
Ruby 1.9.3-p194 and haml_coffee_assets 0.9.0:
Example 1:
%blockquote<
%div
Foo!
Expected:
<blockquote><div>
Foo!
</div></blockquote>
Actual:
<blockquote>Â’
<div>
Foo!
</div>
‘</blockquote>
Example 2:
%img
%img>
%img
Expected:
<img><img><img>
Actual:
<img>
‘<img>
<img>
These examples are from the Haml Reference.
Haml Coffee Assets contains its own version of CoffeeScript. Replace that with the coffee-script
gem. See also #37
This should be possible:
%div{ class: @item.name }
but to make it work, I must done:
%div{ class: "#{@item.name}" }
Otherwise, it works super great. Thanks a lot!
I just switched from using .jst.eco
for my Backbone templates to using hamlc
. I love it so far, soo much cleaner. While updating my templates I am bumping into one issue though, I can't seem to get a null
value to parse nothing.
In my Backbone Model I do:
defaults:
email: null
first_name: null
last_name: null
company: null
This line in eco
shows the company when there is one, and shows nothing when there isn't:
<div class="field">
<label for="company"> company:</label>
<input type="text" name="company" id="company" value=<%= @company %> >
</div>
While the new hamlc
shows the actual text null
inside the input field when no company is provided:
.field
%label{ for: 'company' } company:
%input{ type: 'text', name: 'company', id: 'company', value: @company }
Any ideas?
With my install, the Readme examples don't work as written. Should we update the readme ?
%header
%h2= title
Should be:
%header
%h2= @title
and also,
JST["template"].render(...)
should be
JST["template"](...)
(without render())
I keep my templates in the backbone tree (app/assets/javascripts/backbone/templates
) rather than in the root of javascript assets (app/assets/javascripts/templates
), so I created an initializer with this one line:
HamlCoffeeAssets::HamlCoffeeTemplate.name_filter = lambda { |n| n.sub /^backbone\/templates\//, '' }
When I bind to pry, I can see that the lambda is created properly. I can even call it passing a block and it seems to work properly (i.e. returning "template.hamlc"
ratther than "backbone/templates/template.hamlc"
).
Yet I still have to call JST['backbone/templates/tempalte']()
in order to get the template.
I use Rails 3.1.1
This is my Gemfile:
source 'http://rubygems.org'
gem 'aws-sdk'
gem 'cancan'
gem 'devise', '1.5.3'
gem 'friendly_id'
gem 'haml-rails'
gem 'jquery-rails'
gem 'json'
gem 'mysql2'
gem 'paperclip', '~> 2.7.0'
gem 'rails', '3.1.3'
gem 'rails-backbone'
gem 'simple_form'
# gem 'therubyracer'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.1.0'
gem 'execjs'
gem 'haml_coffee_assets'
gem 'sass-rails', '~> 3.1.0'
gem 'uglifier'
gem 'zurb-foundation'
end
group :development, :test do
gem 'capybara', '~> 1.1.2'
gem 'cucumber-rails', '~> 1.2.1'
gem 'database_cleaner'
gem 'factory_girl_rails', '1.4.0'
gem 'minitest', '~> 2.10.0'
gem 'mongrel'
gem 'pry'
gem 'rspec-rails', '2.7.0'
end
and this is my application.coffee:
#/= require jquery
#/= require jquery_ujs
#/= require foundation
#/= require underscore
#/= require hamlcoffee
#/= require_tree ./backbone/templates
#/= require backbone
#/= require backbone_rails_sync
#/= require backbone_datalink
#/= require_tree ./backbone
maybe I'm missing something, but it seems like config.hamlcoffee.whatever
would throw in environments that don't include the :assets
group. Is there a good way to guard against this?
When I run this in my sprockets pipeline, the output javascript is as follows:
// test.jst.hamlc
(function() {
this.JST || (this.JST = {});
this.JST["backbone/templates/test"] = #cart
%h2= I18n.t('js.cart.title')
- if @cart.length == 0
%p.empty= I18n.t('js.cart.empty')
- else
%ul
- for item in @cart
%li
.item
= item.name;
}).call(this);
It seems like it isn't even detecting/processing haml to html. Any thoughts on this or how to debug why it doesn't work?
Note: I am using Sprockets outside of the Rails asset pipeline (using a Sprockets standalone)
Stuck on this for a couple of hours, not sure what to do with this error in js:
this.JST["login_btn"] = (function(context) {
return (function() {
var $o;
$o = [];
$o.push("<div id='login_btn'></div>");
return $o.join("\n").replace(/\s(\w+)='�true'/mg, ' $1').replace(/\s(\w+)='�false'/mg, '');
}).call(window.HAML.context(context));
I have the repo here: https://github.com/WaleyChen/vekii_2.0.
Could you take a look?
Thank you,
Waley
I just add two gems in my Gemfile and create one template to test and.. it doesn't work
Gemfile
ExecJS::ProgramError in Main#index
Showing C:/preject/app/views/layouts/application.html.haml where line #6 raised:
TypeError: Object doesn't support this property or method
(in C:/preject/app/assets/javascripts/backbone/templates/profile/index.jst.hamlc)
In index.jst.hamlc just:
.qwe test123
Similar to haml syntax following code:
%span.add-on.stats-vote-impact
#{2 + 2}%
Should be parsed as
%span.add-on.stats-vote-impact
= "#{2 + 2}%"
But it throws exception :
ExecJS::ProgramError in Video_channel/polls#show
Showing /var/proj/rp-dev1/app/views/layouts/video_channel.html.haml where line #10 raised:
Unable to parse tag from #{2 + 2}%: TypeError: Cannot call method 'replace' of undefined
(in /var/proj/rp-dev1/app/assets/javascripts/templates/polls/statistics.jst.hamlc)
I have the require to hamlcoffee and require_tree to the assets/templates directory in my application.js.coffee. The gem is required in the assets block of my Gemfile.
My .jst.hamlc files don't get compiled. Instead when loading the application in a browser, I get the following error in the console
clients.htmlc.js GET http://localhost:3000/assets/clients.htmlc.js?body=1 404 (Not Found)
Moreover, there is no JST object available to the Javascript code.
Hello,
Thanks for nice gem.
It looks really cool.
But I can't use it sadly. :(
I'm developing on Windows.
I suppose it cause execjs can't find proper Javascript Runtime.
Then I uninstalled execjs gem.
And installed nodejs, reinstalled execjs gem again.
But it still not work.
How can I fix this problem?
('jst.ejs' work fine)
bundle exec rake RAILS_ENV=development assets:precompile
D:/ruby/bin/ruby.exe D://ruby/lib/ruby/gems/1.9.1/bin/rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
rake aborted!
TypeError: Object doesn't support this property or method
(in D:/testapp/app/assets/javascripts/app/views/posts/index.jst.hamlc)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [D:/ruby/bin/ruby.exe D:/ruby...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Hi there,
New to haml_coffee_assets
so please forgive me if I'm doing something dumb.
The following interpolation with a .hamlc
file causes an error:
%a{ href: "/people?name=#{@name}&page=4" }
Error is:
Uncaught Error: ExecJS::ProgramError: missing ', starting on line $LINE_NUMBER
Changing the href to omit the ampersand after the interpolation prevents the error, as does using + to concatenate strings:
%a{ href: "/people?name=#{@name}page=4" }
%a{ href: "/people?name=" + @name + "&page=4" }
Seems like an ampersand directly after the interpolation is the cause of the error, but I'm not sure exactly why.
Cheers :)
Edit: I'm using haml_coffee_assets
0.9.4.
Hi, I think this is very useful, however there is a problem.
I'm using backbone.js with rails 3.2.2, I created a simple file named hello2.hamlc located at '\app\assets\javascripts\backbone\templates\organizations\hello2.hamlc',
content is simple as below:
%h1 Hello2 HAML
%h1 Listing organizations
%table
%tr
%th Name
%th Parent
%th Organization type
%th
%th
%th
when I browse to the url which requires the hamlc file, I got an error
ExecJS::ProgramError in Organizations#index
so I debugged into haml_coffee, and found an exception raises as below. I have no idea what's going on, could you help me? thanks very much!
C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.8.4/lib/haml_coffee_ass
ets/haml_coffee.rb:122
self.configuration ||= Configuration.new
(rdb:1) pp configuration
#<HamlCoffeeAssets::HamlCoffee::Configuration:0x231e4f0
@basename=false,
@cleanValue=true,
@context="HAML.context",
@customCleanValue="HAML.cleanValue",
@customFindAndPreserve="HAML.findAndPreserve",
@customHtmlEscape="HAML.escape",
@customPrecede="HAML.precede",
@customPreserve="HAML.surround",
@customSucceed="HAML.succeed",
@customSurround="window.HAML.surround",
@escapeAttributes=true,
@escapeHtml=true,
@format="html5",
@namespace="window.JST",
@preserveTags="textarea,pre",
@selfCloseTags="meta,img,link,br,hr,input,area,param,col,base",
@uglify=false>
(rdb:1) p name
"backbone/templates/organizations/hello2"
(rdb:1) p source
"\n%h1 Hello2 HAML\n\n%h1 Listing organizations\n%table\n %tr\n %th Name\n
%th Parent\n %th Organization type\n %th\n %th\n %th\n"
(rdb:1) p jst
true
(rdb:1) s
C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.8.4/lib/haml_coffee_ass
ets/haml_coffee.rb:123
runtime.call('HamlCoffeeAssets.compile', name, source, jst,
(rdb:1) s
C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.8.4/lib/haml_coffee_ass
ets/haml_coffee.rb:140
@runtime ||= ExecJS.compile(source)
(rdb:1) n
C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.8.4/lib/haml_coffee_ass
ets/haml_coffee.rb:148
coffeescript + ';' + haml_coffee + ';' + haml_coffee_assets
(rdb:1) p coffeescript + ';' + haml_coffee + ';' + haml_coffee_assets
SyntaxError Exception: C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.
8.4/lib/haml_coffee_assets/haml_coffee.rb:148: unterminated string meets end of
file
(rdb:1) n
C:/Ruby192/lib/ruby/gems/1.9.1/gems/haml_coffee_assets-0.8.4/lib/haml_coffee_ass
ets/haml_coffee.rb:172
(rdb:1) n
C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/module.rb:27
runtime.compile(source)
(rdb:1) n
C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/external_runtime.rb:
32
eval "#{identifier}.apply(this, #{MultiJson.encode(args)})"
(rdb:1) p "#{identifier}.apply(this, #{MultiJson.encode(args)})"
"HamlCoffeeAssets.compile.apply(this, [\"backbone/templates/organizations/hello2
\",\"\\n%h1 Hello2 HAML\\n\\n%h1 Listing organizations\\n%table\\n %tr\\n %t
h Name\\n %th Parent\\n %th Organization type\\n %th\\n %th\\n %t
h\\n\",true,\"window.JST\",\"html5\",false,false,true,true,true,\"HAML.escape\",
\"HAML.cleanValue\",\"HAML.surround\",\"HAML.findAndPreserve\",\"window.HAML.sur
round\",\"HAML.succeed\",\"HAML.precede\",\"textarea,pre\",\"meta,img,link,br,hr
,input,area,param,col,base\",\"HAML.context\"])"
(rdb:1) n
C:/Ruby192/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/context.rb:179
annotate_exception! e
(rdb:1)
When using "=>" context feature of CoffeScript it prepends the
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
to properly handle it in JS. This prefix appears before your function(context) {
wrapper. Which leads to
this.JST["..."] = var __bind = function(fn, me){ ret
which is a syntax error.
Is there a way to access images or other assets from within a template? In a normal Rails view using Haml you would just do something like:
= image_tag(asset_path("images/rails.png"), :alt => "Rails!")
And it will link you to the cache-buster version of the file: rails-abcd1234efab.png
(I think also just image_tag("rails.png") might do the same thing but I'm unsure)
Is there a method that will automatically do that for me here, or should I name a file index.jst.hamlc.erb
if I need to include other asset pipeline files and add this:
%img{:src => "<%= asset_path("images/rails.png") %>", :alt => "Rails!")
That feels a little cumbersome...but if there's no other solution it might work (Haven't actually tested it yet).
This asset fails to compile:
#page{:style => 'font-family: "Lucida Grande", "Verdana"; text-align: center'}
.content{:id => @yield()}
And this does not:
#page{:style => 'text-align: center'}
.content{:id => @yield()}
When I run rails project in production mode on local machine and open /assets/application-286367ee0c04b437bb18d2ede3e221cf.js I see the following error -
throw Error("Sprockets::FileNotFound: couldn't find file 'hamlcoffee'\n (in /project/app/assets/javascripts/application.js:21)")
21 line -
//= require hamlcoffee
I open gem source code
gem open haml_coffee_assets
and hamlcoffee.js.coffee.erb file in the right place.
What is interesting, in development mode or on heroku this error does not occur. I can't even imagine why this error happens. @netzpirat, please help figure out.
I got parse error when using HTML comments in HAMLC code with { or }
for example
/ %a{:href=>''}
But Coffee code comment work ok in this case
-# %a{:href=>''}
reports error
TypeError: "toString"
the generated javascript not work with cscript.
after install node.js on windows, it works agian
In the following template, the single quote in the title attribute is converted into a double quote:
%a{ href: '#', title: "This shouldn't be a double quote" } But it is
This produces the following HTML:
<a href='#' title="This shouldn"t be a double quote">But it is</a>
As a result, the title is displayed at:
This shouldn"t be a double quote
Instead of converting '
to "
, it should be converted to '
or '
.
Hi,
I'm trying to run my Rails 3.2.2 app in production env. Trying to start up the Rails instance results in
/Users/nicholas/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `hamlcoffee' for #<Rails::Application::Configuration:0x007fd98badfc98> (NoMethodError)
from /Users/nicholas/code/src/clients/commandfusion/Integrator-Portal/config/application.rb:66:in `<class:Application>'
This is issuing from some config I'm setting up in application.rb.:
#haml_coffee_assets config
config.hamlcoffee.escapeHtml = false
config.hamlcoffee.escapeAttributes = false
config.hamlcoffee.cleanValue = false
Just wondering if you've come across this before? I'm using the latest version of your gem, 0.8.4. Running the app in the dev or test environments is fine.
Haml_coffee_assets has been a pleasure to use so far, thanks for providing it.
Cheers,
Nicholas
Here is a .hamlc template I am having trouble with:
%td= new Date(@transaction.get('posted_at')).toString('M/d/yyyy')
%td= @transaction.escape('description')
%td= @transaction.debit()
%td= @transaction.credit()
%td= @transaction.running_balance()
This compiles down to the final javascript template thus:
(function() {
this.JST || (this.JST = {});
this.JST["transactions/show"] = (function() {
var _ref;
if ((_ref = window.JST) == null) {
window.JST = {};
}
window.JST['transactions/show'] = function(context) {
var fn;
fn = function(context) {
var c, e, o;
o = [];
e = HAML.escape;
c = HAML.cleanValue;
o.push("<td>" + (e(c(new Date(this.transaction.get('posted_at')).toString('M/d/yyyy')))) + "</td>");
o.push("<td>" + (e(c(this.transaction.escape('description')))) + "</td>");
o.push("<td>" + (e(c(this.transaction.debit()))) + "</td>");
o.push("<td>" + (e(c(this.transaction.credit()))) + "</td>");
o.push("<td>" + (e(c(this.transaction.running_balance()))) + "</td>");
return o.join("\n");
};
return fn.call(HAML.context(context));
};
}).call(this);;
}).call(this);
I noticed that the template is null/undefined when I try to use it in my backbone view, so I started tracing back to see where it was getting set figuring I had the order of imports wrong or something. The interesting thing that I found was that the above javascript was getting called before my view code looked for the template and it was also adding the template to window.JST! When I put a breakpoint before the line that reads "}).call(this);;" (basically stopping just before the call to .call(this)) and check the value of window.JST['transactions/show'] it is the function as expected. If I step on more line however window.JST['transactions/show'] is now undefined.
This is my first hamlc template (I've been using ECO), so it's very likely I'm just doing something wrong, but I haven't been able to figure it out and any help would be greatly appreciated.
.share-notebook{ title: 'bar', |
bar: 'foo' }
renders as:
$o.push("<div class='share-notebook'>{ title: 'bar', | \n bar: 'foo' }\n</div>");
The latest Sprockets is giving me errors when I try to put my templates directory directly in app/assets.
Uncaught Error: Sprockets::FileOutsidePaths: /Users/dorje/work/cms/app/assets/templates/about.hamlc isn't in paths: /Users/dorje/work/cms/app/assets/images, /Users/dorje/work/cms/app/assets/javascripts, /Users/dorje/work/cms/app/assets/stylesheets, /Users/dorje/work/cms/vendor/assets/images, /Users/dorje/work/cms/vendor/assets/javascripts, /Users/dorje/work/cms/vendor/assets/stylesheets, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/haml_coffee_assets-0.4.0/vendor/assets/javascripts, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/rails-backbone-0.5.5/vendor/assets/javascripts, /Users/dorje/.rvm/gems/ruby-1.9.2-p290/gems/jquery-rails-1.0.19/vendor/assets/javascripts
It also gives me much cognitive dissonance not to put my templates with the rest of my JS application.
Is there a way I can configure the app to view a certain directory as the base dir? I've been reading through all kinds of Tilt stuff but I can't quite figure out what this scope.logical_path stuff is about.
Hi Michael!
Thanks for haml_coffee_assets, however we had a big issue last week when we first try to deploy our Universal Real-Time Statistics Demo page with haml_coffee_assets 0.8.2. It seemed that the assets where not well pre-compiled (there was a dummy JS error, nothing more), we couldn't find really the cause of it, the only thing that I did find is that by reverting to 0.7.1, everything was working again (so it fails with 0.8.2, 0.8.1 and 0.8.0).
So I think there might be an issue in these commits, maybe in this line, I can't see any other significant changes...
Thanks for the help!
Empty lines broke the template:
#cart
%h2= I18n.t('js.cart.title')
- if @cart.length == 0
%p.empty= I18n.t('js.cart.empty')
- else
%ul
- for item in @cart
%li
.item
= item.name
%a{ :href => "/cart/item/remove/#{ item.id }" }
= I18n.t('js.cart.item.remove')
my hamlc file:
%a#select_person_button(href="#select_person" data-role="button" data-inline="true")
is translated into
If I change "true" to "True", then the result is correct
I comment out line 706 of lib/js/haml-coffee.js like this:
//value = "'" + key + "'";
then it works, but I'm not sure the patch is correct.
The following haml works in a haml template but not in a hamlc template:
%div <div class="strong"><p>Hello world!</p></div>
The exeception thrown is Error: Parse error on line 2: Unexpected 'IDENTIFIER'
.
It'd be great to support it so that for example some rails view helpers can be used:
%span Here's the link: <%=content_tag("a", "Test", href: "http://www.example.com", target: "_blank")%>
I think you might need to add the vendor directory to your gemspec. Using the gem as a git repo works fine.
When I run "bundle exec rake RAILS_ENV=production assets:precompile", hamlc templates are not compiled. They are just put as is in the /assets directory.
On-the-fly compilation (like in development mode) works perfectly though.
Did I miss something ?
It's broken because String.trim
doesn't exist in all browsers.
This is the commit that broke it: e8185f5#commitcomment-1537573
Want me to draft a fix?
Not sure if it's a bug, but some existing code got broken.
> test1 = "%label{:for => 'gods_sake'} It fails (whyyyyy?)"
> HamlCoffeeAssets::HamlCoffee.compile 'test1', test1, false
ExecJS::ProgramError: Error: unclosed ( on line 4
from /home/alerticus/.rvm/gems/ruby-1.9.3-p125/gems/execjs-1.3.1/lib/execjs/external_runtime.rb:68:in `extract_result'
# but it works as expected with the linebreak and indentation
> test2 = "%label{:for => 'gods_sake'}\n It fails (whyyyyy?)"
> HamlCoffeeAssets::HamlCoffee.compile 'test2', test2, false
=> "(function(context) {\n return (function() {\n var $o;\n $o = [];\n $o.push(\"<label for='gods_sake'>\\n It fails (whyyyyy?)\\n</label>\");\n return $o.join(\"\\n\").replace(/\\s(\\w+)='true'/mg, ' $1').replace(/\\s(\\w+)='false'/mg, '');\n }).call(HAML.context(context));\n});"
Hi netzpirat,
I tried to use I18n in hamlc file likes below.
%span= I18n.t('text.test')
And It gave me a message below.
Error: I18n is not defined Source File.
P.S. Could I use render , form_for in haml_coffee_assets?
.whatever { data: { :'some-thing' => 'foo' } }
Parses as
$o.push("<div class='whatever'>{ data: { :'some-thing' => 'foo' } }</div>");
As far as I can tell, it's not possible to use dashes in any way. strings don't work on the left hand side either.
Hi I've been trying to deploy but it keeps on failing on assets precompile.
can't modify immutable index
haml_coffee_assets-1.4.1/lib/haml_coffee_assets/rails/engine.rb:19:in `block in class:Engine'
I'm using 1.4.1 with sprockets 2.1.3 and rail ties 3.2.7
I'm trying to get the gem setup for development. I followed the current README:
application.rb
, around a if defined? ::HamlCoffeeAssets
if block: n.sub /^backbone\/templates\//, ''
But when I type JST
in the javascript console, I see the old path of my templates: backbone/templates/path/to/template
. Howcome it doesn't seem to register?
If you need more information I'd be happy to give it.
Should something like this work?
%ul.avatars{:class => ("all-shown" if @allShown?) }
I tried a few combinations but couldn't get a class to be added conditionally.
%textarea
= @title
compiles to
function (context) {
var fn;
fn = function(context) {
var c, e, o;
o = [];
e = HAML.escape;
c = HAML.cleanValue;
o.push("<textarea>undefined</textarea>");
return o.join("\n");
};
return fn.call(HAML.context(context));
}
This only happens with textareas... any idea what's happening ?
The following should be valid haml/coffeescript, but causes an unmatched OUTDENT
error:
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, length: 3 ) }
However, it only breaks in the context of haml. This compiles without error:
= myFunction(@number, length: 3)
These other syntaxes don't work:
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, { length: 3 }) }
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, 'length': 3 ) }
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, { 'length': 3 } ) }
The only syntaxes that work require the key to be quoted, and separated from the colon by a space. Curly braces are optional:
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, { 'length' : 3 } ) }
%input{ type: 'text', name: 'padded_number', value: myFunction(@number, 'length' : 3 ) }
I noticed some strange behaviors when using a space between an attribute and its :
.
/ Works well.
%span.value{ 'foo': 'foo', 'bar': 'bar', baz: 'baz' } Foo
/ <span class="value" foo="foo" bar="bar" baz="baz">Foo</span>
/ Throws error. ExecJS::ProgramError: Unable to parse tag.
/ %span.value{ 'foo' : 'foo', 'bar' : 'bar', baz: 'baz' } Foo
/ It only throw error when the space is after the first attribute !?
/ Works weird: no error despite the space but fucked HTML.
%span.value{ 'foo': 'foo', 'bar' : 'bar', baz: 'baz' } Foo
/ <span class="value" foo="foo", "bar" :"bar" baz="baz">Foo</span>
/ Less strange in data attribute: the attribute is just not displayed:
%span.value{ data: { 'foo' : 'foo', 'bar': 'bar' } } Foo
/ <span class="value" data-bar="bar">Foo</span>
So I stick with foo: 'foo'
or 'foo-foo': 'foo'
for keys.
But I thought it was important to point that bugs out as they can drive you crazy.
Hi, in my configuration I have:
config.hamlcoffee.escapeHtml = false
config.hamlcoffee.escapeAttributes = false
config.hamlcoffee.uglify = true
But whenever I pass HTML into JST it is escaped anyway, e.g.:
JST['template']({title: "<p>asd</p>"})
Will return
<header>
<h2><p>asd</p></h2>
</header>
There doesn't seem to be anything unusal about my Gemifle setup, I'm using Rails 3.2 on Ruby 1.9.3, with haml and coffee everywhere.
Not really want to hunt the reason down, so here is the broken template:
%label.g-label{:for => 'input-transfer-template-repeat-number'} Время:
%input#input-transfer-template-repeat-number.g-field{:type => 'text', :name => 'transfer_template[repeat_number]', :placeholder => 'например, 14:50'}
It fails with ActionView::Template::Error Error: Parse error on line 5: Unexpected 'STRING'
Looks like it's because of the UTF-8 in placeholder attr.
This input doesn't seem to work anymore in 1.1.1:
%div(foo="#{func('foo')}" bar="bar")
Diff between 1.1.0 and 1.1.1 output:
--- regression_1.1.0.js 2012-07-04 12:13:02.000000000 +0200
+++ regression_1.1.1.js 2012-07-04 12:14:31.000000000 +0200
@@ -2,11 +2,11 @@
this.JST || (this.JST = {});
this.JST["regression"] = (function(context) {
return (function() {
- var $o;
+ var $o, bar;
$o = [];
- $o.push("<div foo='" + (func('foo')) + "' bar='bar'></div>");
+ $o.push(("<div foo='" + (func('foo')))(bar = "bar'></div>"));
return $o.join("\n").replace(/\s(\w+)='�true'/mg, ' $1').replace(/\s(\w+)='�false'/mg, '');
Hi
I am trying to use rails helpers in my .hamlc templates (e.g. image_tag, route helpers), but they are not processed. Instead, they are getting sent to the client as javascript methods to be called when rendering the template.
What do I need to do to use rails helpers in my haml templates?
Hello,
I encountered an error in your gem. My hamlc template contains a line:
%input{name: 'name', type: 'text' }
The error is that html output for the line is:
<input name="" type="text">
So, if an input has name "name", the gem generates html tag with an empty name attribute.
Thank you in advance.
Currently it generates the full JST template trying to shorten the names.
I did similar thing in my pakunok gem for hamljs. Did it even smarter when ot was producing the plain function names for subdirectories.
But after some discussions and considerations decided to stick to rails conventions
This resulted in a separate gem (ruby-haml-js).
It might look like a good idea to automatically attach the template to JST.
But this is not how it is supposed to be.
Hi,
can I use this gem with Sinatra, and if yes could anybody indicate me the easiest solution to do this?
Thx in advance
Michał
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.