In Middleman, how can I use the srcset attribute, and with relative file paths? - middleman

In Middleman, I can generate a relative image file path like so:
<%= tag :img, :src => "/images/down-caret-1x.png" %>
Which will output this:
<img src="/images/down-caret-1x.png">
I'd like to get an output that looks like this:
<img src="/images/down-caret-1x.png" srcset="/images/down-caret-2x.png 1000w">
Anyone know how to do that?
The docs mention using this:
<img src="<%= image_path('100px.jpg') %>" srcset="<%= image_path('300px.jpg') %> 3x, <%= image_path('200px.jpg') %> 2x, <%= image_path('100px.jpg') %> 1x">
but I don't see anywhere to set the image_path variable or whatever that is.
Thanks

You set it in your config.rb like this:
set :images_dir, "path/to/images"
I found this blog quite useful for configuring middleman: https://richardkall.se/building-static-websites-with-middleman-part-two/

Related

Display link to in table open file in classic asp

I have set for files in Upload folder. Also file name & file created date is stored in Database. Now
I have to bind the table with record set & provide link to download file . How I can achieve this ? All uploaded files present in Upload Folder. Below is my code for the same.
<%
Do While NOT FileResultStatus.Eof
%>
<tr>
<td> <%= FileResultStatus.Fields("sr") %> </td>
<%
Dim link
link = Server.MapPath("Upload")
link = link +"\" + FileResultStatus.Fields("filename")
%>
<td> <a href= "<%= link %> "</a> <%= FileResultStatus.Fields("filename") %> </td>
<td> <%= FileResultStatus.Fields("records") %> </td>
</tr>
<%
FileResultStatus.MoveNext
Loop
%>
</table>
<%
FileResultStatus.Close
Set FileResultStatus=nothing
Connection.Close
Set Connection=Nothing
%>
I am not sure what your problem or question is. Please state more clearly what is not working.
Given that you are referencing the recordset in a correct way, there is one thing in that code that looks odd. The Server.MapPath function returns the physical path of Upload, i.e.something like C:\inetpub\wwwroot\my-application\Upload which is clearly not what you want as a href in your link. You want link like href="Upload/myfilenameFromRecordset.txt".
The link should be a relative path to the file uploads folder, not the physical path.
In your browser just type in the location to one of the known files and use that as the link.
For example, if your download link that you type in looks like:
http://yourserver/Upload/filename.ext
then your code should be:
Dim link
link = "Upload/" + FileResultStatus.Fields("filename")
You may have to experiment with the above or
link = "./Upload/" + FileResultStatus.Fields("filename")
depending on your setup

How do I link_to VIEW a pdf resource (NOT download) in a custom engine on RefineryCMS?

I'm a novice RoRr and I'm building my company's website on RefineryCMS.
I've properly created an engine for my Boss' publications, within which I included a pdf:resource column and have uploaded all the articles to my backend. Everything works - renders properly and downloads work.
HOWEVER, I also want to be able to view those pdf's as a _blank target through a link_to on the article.title. SEE CODE BELOW !!!XXXXXXXXX_path , or any useable variation, is what I'm looking for!!!
The important thing is that the corresponding PDF is being rendered. That is, I know I can't manually code individual links while using the [.each do] loop.
I'm sure there is a way to get this done but, as I said, I'm a novice and could use some help.
here's the code:
<section id="body_content">
<section id="body">
<section id=articles>
<% #articles.each do |article| %>
<div class=wrapper>
<div class=particle>
<h1><%= link_to article.title, **(XXXXXXXXXXXXXXX.pdf)**, :target => '_blank' %></h1>
<p><span class=publisher><%= article.publication %></span>,
<span class=year><%= article.year %></span>
</p>
<% if article.pdf.present? %>
<%= link_to image_tag("/assets/pdf.png", :size => "30x30"), article.pdf.url, :title => "PDF download", :class => "pdflink" %>
<% else %>
pdf
<% end %>
</div>
<% end %>
</div>
</section>
</section>
Any help is much appreciated.
*SIDE NOTE: my next task is to add a link to email the article (as an attachment) to a third party. Again, I'd imagine there's something in ActionMailer that can help with this but any help before I get started would be great.
much obliged.
Sorry I read your question wrong. Try this instead
To indicate to the browser that the file should be viewed in the browser:
Content-Type: application/pdf
Content-Disposition: inline; filename.pdf
To have the file downloaded rather than viewed:
Content-Type: application/pdf
Content-Disposition: attachment; filename.pdf

How to compute path to file in public folder?

I created a folder called Uploads in my public folder.
I'd like to have people be able to click a link and download a file in that Uploads folder.
Here's my code:
<p>
<b>Certifications</b>
<%= link_to #tutor.tutor_degrees.first.name, # => "AS Level English"
root_path + #tutor.tutor_degrees.first.certification_scan %>
</p>
http://localhost:3000/Screen%20shot%202013-02-04%20at%206.01.11%20PM.png
It's missing the /uploads/ bit in the URL path.
If I add that string manually, I get a borked URL:
<p>
<b>Certifications</b>
<%= link_to #tutor.tutor_degrees.first.name,
root_path + '/uploads/' + #tutor.tutor_degrees.first.certification_scan %>
</p>
http://uploads/Screen%20shot%202013-02-04%20at%206.01.11%20PM.png
Try this...
<%= link_to #tutor.tutor_degrees.first.name, "http://#{request.host}/uploads/#{#tutor.tutor_degrees.first.certification_scan}" %>
must work :)

Using Middleman Tags

I am wondering if someone could explain how I can utilise tags in an article.
The documentation states that by default the blog extension should allow you to access tagged articles via tags/blogging.html. http://middlemanapp.com/guides/blog
I guess I'm not sure if I need to create this dir (tags/blogging.html) or if its generated for me?
Then I'm wondering how to create a list of tags, each with a URL that points to this tag template.
I've added this example tag data to the front matter of a few of my articles.
---
title: My Middleman Blog Post
date: 2011/10/18
category: music
tags: blogging, middleman, hello, world
---
my index.html.erb looks like this:
<section class="article-index music">
<% data.blog.articles.each_with_index do |article, i| %>
<% if article.category == 'music' %>
<article>
<h2><%= article.title %></h2>
<time pubdate><%= article.date.strftime('%b %e') %></time>
<span class="categories"><%= article.tags %></span>
<%= article.summary %>
</article>
<% end %>
<% end %>
</section>
This is outputting all my articles, with a title, date, all tags and a summary.
I'm assuming you need to loop through all the tags and output each in a URL of its own, but I'm not really sure of the best way to do this.
At a guess I'm assuming its something like:
<% article.tags.each do |tag| %>
tag
<% end %>
Any help is appreciated.
Thanks
By combining the other answers I have come up with this solution.
<% article.tags.each do |tag| %>
<%= link_to tag, tag_path(tag) %>
<% end %>
It has the benefit of using a generated path, rather than the hardcoded one.
Tags for all articles can be retrieved with the following:
<% blog.tags.each do |tag, articles| %>
<%= link_to tag, tag_path(tag) %> (<%= articles.size %>)<br />
<% end %>
This is exactly what I have on my blog:-
Blog
Github
Currently, you'd have to do it like so:
<% article.tags.split(", ").each do |tag| %>
tag
<% end %>
Assuming your tags are separated with a comma and a space.
I write my tags in the frontmatter as an array
tags : [ accessibility, standards ]
Then I can just loop through them
In HAML it would ne
- current_page.data.tags.each do | tag |
Not supported in 2.0. Possibly in upcoming 3.0
This works perfectly for me in HAML for just displaying the tags, no links
%p= article.tags.join(', ')

Is it possible to use partials to be rendered as wrappers in Rails?

I would like to render structures like this:
<tag1>
<tag2 someattribute="somevalue">
<.. lot of things inside ..>
</tag2>
</tag1>
<tag1>
<tag2 someattribute="someothervalue">
<.. different inside things inside ..>
</tag2>
</tag1>
The tag1, tag2 are the same, they are just parametrized. The inner part of the code changes. I tried to implement the thing above like that (haml):
%div{id:['products', id]}
.products_content
%div{id:['products', id, 'content'], class:'products_mask'}
= yield
This was the partial _content_head.html.haml, which is called from a template:
= render 'shared/content_head', id: 'all' do
%h3= Title
%p= Body of the text.
My theory that yield inside the partial would lead to rendering of the passed block did not prove. Is there a way to use partials as code wrappers? Can you suggest me some solution how to reach this? Thank you.
This might be a good use of the capture method.
I'm only familiar with ERB, but here is the general idea:
<% structure = capture do %>
<h3>Title</h3>
<p>Body of text</p>
<% end %>
Then pass the variable into the partial:
<%= render 'shared/content_head', :structure => structure %>
And within the partial, spit out the structure variable:
<%= structure %>
Reset structure multiple times within the view as you render partials (or maybe more appropriately, in a helper?).
I've used the following (Rails 4, but I think it should work with Rails 3 too):
<%# app/views/users/_edit.html.erb %>
<%= render layout: 'modal_wrapping' do |f| %>
<%= f.input :email %>
...
<% end %>
.
<%# app/views/users/_modal_wrapping.html.erb %>
<div id='modal'>
<%= simple_form_for #user do |f| %>
<%= yield f %>
<% end %>
</div>