-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How I can pass some data? #20
Comments
Yeah, that's exactly what I want to know. As far as I know, there is no way to pass values to |
I know how do it, but it is a little bit dirty. Before piping, generate a part of haml file based on our data. Like this (Coffeescript):
Where magic is function which convert js value to literal equivalent: What do you think about it? |
@iserdmi Thanks! |
A cleaner solution would be a custom slimrb wrapper (or a PR on slim-template/slim) adding a command line option to interpret a JSON string as local data, like so:
where the def set_opts(opts)
#...
opts.on('-d', '--data JSON', 'Interpret a JSON string as local data') do |json|
@options[:data] = JSON.parse json
end
#...
end ... and here: def process
# ...
data = @options.delete(:data)
result =
if @options[:erb]
# q: How to inject data here?
require 'slim/erb_converter'
ERBConverter.new(file: @options[:file]).call(@options[:input].read)
elsif @options[:compile]
# q: How to inject data here?
Engine.new(file: @options[:file]).call(@options[:input].read)
else
# data can be injected into the render call here:
Template.new(@options[:file]) { @options[:input].read }.render(Object.new, data)
end
#...
end Finally, something like this args.push "--data #{JSON.stringify options.data}" if options.data could be added to the index.coffee. What are your thoughts on this? Happy Holidays, |
I've added a |
@dmke It's really great! |
Seems it got accepted, when should we expect this feature to be available in gulp-slim too? Can't wait for it! ^_^ |
+1 on this. |
I have no idea, when a new version is released. In the meantime you can get the master version with some additional steps:
Every now and then I recommend to run |
Thanks for @dmke , now gulp-slim v0.1.0 has been released! ;) |
I have installed ruby,gem, slim
have error
|
@borm, i think that problem is in your explore.slim file - you use 'title' variable that not declared in 'data' option |
Oh, sorry
|
can you show me your explore.slim file? |
Full explore.slim
|
Use this syntax to operate an object's properties: |
Yes, its work, thanks Passing Data into the Template
|
I think that it is an error in gulp-slim documentation. Gulp-slim converts data object to Hash not to Object |
Okey, thanks again, my problem is resolved |
Hello. How can I pass local variables to my haml file? For example with jade I can do something like this:
The text was updated successfully, but these errors were encountered: