sstephenson / ruby-ejs Goto Github PK
View Code? Open in Web Editor NEWEJS (Embedded JavaScript) template compiler for Ruby
License: MIT License
EJS (Embedded JavaScript) template compiler for Ruby
License: MIT License
I feel like an idiot for not being able to figure this out, but here goes.
In rails, my assets/javascripts/foo.jst.ejs file is served up as localhost:3000/assets/foo and assets/foo.js, but localhost:3000/assets/foo.ejs gives a routing error. I have some framework code that insists on calling it with the .ejs extension.
I think this should be an simple config somewhere in the asset pipeline, but I can't find it. I realize it is more of and rails question, but perhaps somebody here recognizes this?
Hello, unfortunately I catch the error with Rails 4.1 and els 1.1.1 while blotting my application:
(ejs 1.0.0 works fine)
/Users/alex/.rvm/gems/ruby-2.1.1/gems/jquery-rails-2.1.4/lib/jquery/rails/railtie.rb:9:in `block in <class:Railtie>': undefined method `join' for nil:NilClass (NoMethodError)
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/application.rb:121:in `initialize'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/railtie.rb:171:in `new'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/railtie.rb:171:in `instance'
from /Users/alex/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/application.rb:90:in `inherited'
I have a problem when I try to use something like
<%- null_var || "some string" %>
in my .jst.ejs template, it evaluate as "null" || "some string"
which always return "null"
string
So it's work If I do <%- (null_var || "some string) %>
or <%- "%s", null || "some string" %>
it should be bug
Pleas fix this for clean code, Thanks :)
Is there any way to get partials working?
I just tried to do it with <%= this.partial('some_partial'); %>
but it doesn't work. I looked it up in the source and think it's not implemented yet, is it?
This library has opposite conventions from what other libraries expect, such as the official NPM version: https://www.npmjs.com/package/ejs . This is also the convention used in Ruby's native erb
templates.
Per the Principle of Least Surprise this library should follow the conventions of the more popular libraries that already exist.
This is a mirror of a bug on Sprockets as it affects either.
The problem is this: EjsTemplate
passes data to EJS.compile
which uses gsub!
in its implementation. When used with Rails, data is an ActiveSupport::SafeBuffer
whose gsub!
is messed up at the moment and breaks $1
, so the EJS compiling fails.
Should EjsTemplate force data
to be a regular string with to_str
or should that be EJS's job to make sure the input is a regular string?
I've made a committed fix on ruby-ejs' end for now quick use. If that's the best place to convert SafeBuffers to strings, I can just make a pull request or you can pick a cherry.
I think it would be nice if the EJS Javascript file would be added to this gem, so that people don't have to download it and place in the lib or vendor folder.
Hello, Stephenson
I'm getting the following exception when I try to compile a template function without any variables.
Uncaught ReferenceError: id is not defined
Suppose I have the following template:
<span data-id="<%= id %>"><%= content %></span>
And I run this with the function:
JST["template"]()
It won't work.
Using Rails 3.1.1 with Asset Pipeline.
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.