Get Current Path of Page in Middleman Layout File - ruby

Is it possible to retrieve the current path of a page in a middleman file? For instance, if I have a layout file layout.erb with something like the following:
<%= page.path %>
<%= yield %>
and a test file index.html:
Testing
then when Middleman rendered the page I would get something like:
/index.html
Testing

Middleman also provides the current_page variable. current_page.path is the source path of this resource (relative to the source directory, without template extensions) and current_page.url is the path without the directory index (so foo/index.html becomes just foo).
<%= current_page.path %>
# -> index.html
<%= current_page.url %>
# -> /
Details from Middleman's Middleman::Sitemap::Resource rubydoc.
http://rubydoc.info/github/middleman/middleman/Middleman/Sitemap/Resource

The solution is:
<%= request.path %>

Related

How can I generate a link/route/path in Roda?

How can I generate a path or URL in a view in Roda?
Will I need to use a plugin? If not, how else? Or will I have to hard-code urls/paths?
In Rails I'd do this way:
<%= home_about_path %>
To just generate urls based on set semantics, you want the path plugin.
Usage looks something like this:
App < Roda
plugin :path
path :post do |post|
"/blog/#{post.id}"
end
end
And then, in your templates similarly to how you would use something_path in Rails:
<%= #post.title %>

File traverse and read failure in Vagrant / Puppet setup

I have a Vagrant / Puppet set up in which I am attempting to generate a bunch of configuration files and then concatenate them into a master file.
The individual files are generated and written to a conf directory and the last action is to create the master file which uses an erb template to read the files in the conf directory.
<% files = Dir["/etc/sysconfig/iptables/conf/*.conf"] -%>
<% files.each do |name| -%>
<% file = File.open(name) -%>
<% contents = file.read -%>
<%= contents %>
<% end -%>
When I run "vagrant up", everything appears to run correctly but the master configuration file is empty. I have checked the timestamps on the conf directory and the master configuration file and they are correct to (The master config file is created after all the individual config files).
If I ssh into vagrant and run "puppet apply" manually, the master config file is created as expected. I have tried using a bash script instead of the erb method but encountered the same problems.
Does anyone have any ideas what might cause this?
Puppet expands templates at manifest compile time. The content you are trying to catenate is only available at catalog application time.
Have you looked at the concat module? It will likely make short work of your task.

Rails 4 image_path('image.jpg') displays image path instead of actual image.

Running Rails 4 and deployed to Heroku and have been struggling with a strange issue.
Config contains:
config.assets.compile = true
Gemfile contains:
gem 'rails_12factor', group: :production
Have a line in my application.html.erb to render an image:
<%= image_path('image.jpg') %>
Placed my image in the following locations (excessive but troubleshooting):
assets
assets/images
public
public/images
I am compiling assets during my deployment to Heroku (slug compilation) and no errors are returned.
When I open the webpage the image is not rendered and instead the path is provided as:
"/images/image.jpg"
Any thoughts as to why this is occurring?
Thank you all in advanced
That is the expected behaviour for image_path. I think what you're looking for is image_tag.
For example, if your image is assets/images/image.png to render it in the view you would use:
<%= image_tag('image.png') %>
That is the recommended method, but you could also do
<img src="<%= image_path('image.png')%>" />

Render SASS files correctly in File.read (inside PDF file)

I generate a pdf and have to include css in the generated file so that the styling is correct in the pdf. To do this I have
<%= File.read(Rails.root.join("app", "assets", "stylesheets", "application.css.scss")) %>
<%= File.read(Rails.root.join("app", "assets", "stylesheets", "app.css.scss")) %>
But the sass isn't templated correctly. Does anyone know what the correct code to render the files right are?
replace File.read with
YourApp::Application.assets["application.css.scss"].to_s.html_safe
where YourApp is the name of the application you are working on. This will cause rails to render the scss inline.

Can't get asset pipeline working

I can't get the asset pipeline working for some reason. I get a 404 on request to both application.css and application.js. I'm using rails 3.1.0.rc6. Nothing special, just created a new project.
In my layout file:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
It's linking to /stylesheets/application.css and same with the js file. I'm using pow but also tried starting the server with webrick.
Any ideas?
Note: using sprockets 2.0.0.beta.15
Figured it out. I had to make an explicit require call to "sprockets/railtie"
You might find that adding
config.serve_static_assets = true
to your config/environments/xxx.rb will help.
To be more exact, add this to your Gemfile
gem 'sprockets/railtie'

Resources