iterating over yaml data in middleman template - ruby

I have a list of projects in a yaml file which i'd like to dynamically loop thru for a template in a middleman app but am unsure how or if I even can/should do it more dynamically.
I have:
data.projects.each do |f|
proxy "/work/#{f[:name].parameterize}.html", "/work/template.html",
:locals => { name: f[:name], client: f[:client], ... } #would like to dynamically pull in keys as locals.
end
ignore "/work/template.html"
Yaml:
- name: Acme Website
client: Acme Inc
overview: "Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw."
skills:
- design
- development
- branding
- ecommerce
stack:
- middleman
- branding
- design

Maybe you could just use the full projectobject within your templates?
data.projects.each do |p|
proxy "/work/#{p[:name].parameterize}.html", "work/template.html",
:locals => { :p => p }
end
... should give you access to your project within http://0.0.0.0:4567/work/acme-website.html:
<ul>
<li><%= p.name %></li>
<li><%= p.client %></li>
</ul>
Result:
Acme Website
Acme Inc

First you need to parse the YAML back into a Ruby object, then go from there:
require 'yaml'
doc = YAML.load(<<EOT)
---
- name: Acme Website
client: Acme Inc
overview: "Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw."
skills:
- design
- development
- branding
- ecommerce
stack:
- middleman
- branding
- design
EOT
require 'pp'
pp doc
Which outputs:
[{"name"=>"Acme Website",
"client"=>"Acme Inc",
"overview"=>
"Cupcake ipsum dolor sit amet wafer gummi bears pudding applicake. Jujubes brownie powder. Sweet roll powder gingerbread gummies. Cupcake ice cream sweet roll pie lollipop. Jelly-o jelly-o apple pie chupa chups jelly jujubes gingerbread. Icing carrot cake powder chupa chups. Pudding sweet roll jelly-o muffin faworki biscuit. Marzipan marshmallow cake tiramisu caramels bear claw carrot cake cotton candy. Toffee danish sweet roll. Cookie topping powder toffee ice cream muffin dragée. Soufflé caramels apple pie chocolate cake cookie cake. Macaroon tiramisu halvah soufflé. Dessert toffee halvah chocolate cake bear claw.",
"skills"=>["design", "development", "branding", "ecommerce"],
"stack"=>["middleman", "branding", "design"]}]
That's an array of hashes. You can iterate over the returned array, and extract the embedded hashes and process them normally:
doc.each { |h|
puts h['name']
puts h['client']
}

Related

Dompdf text not wrapping in table cell

Can someone explain this to me please, i have a Laravel app (probably not important) and am using dompdf when i use the HTML below
<head>
<style type="text/css">
</style>
</head>
<body>
<table style="width:100%;">
<tr>
<td>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</td>
</tr>
</table>
</body>
</html>
out of the box i get this....
Why does the text not wrap around, and why does it go off the screen, am i missing something really obvious?
Thanks
Some style not working on dom-pdf so for now just try with giving black solid border of 1px to
Just add this code in your CSS:
td {
border: 1px solid black;
}
Adding style="white-space:wrap" worked for me. It justifies the text and matches the cell width.
<td style="white-space:wrap">My long text goes here. My long text goes here. My long text goes here. My long text goes here. My long text goes here. My long text goes here. My long text goes here. My long text goes here. My long text goes here.</td>

Lucene cartesian product diferent documents?

I have 3 indexed documents:
Cars: Toyota (gt, gtX, gtx12), Ford (corola...), Volkswagen (gtS), Tesla...
Car models: gt, gtX, gtx12
Car colors: white, red
Example search query: "gt*"
Should return:
Volkswagen gtS white
Volkswagen gtS red
Toyota gt white
Toyota gt red
Toyota gtx12 white
Toyota gtx12 red
Toyota gtX red
Toyota gtX white
I can't add them to index like 'Toyota gt', 'Toyota gtx'... because there will be a relay huge index (even more then 50gb in my case, and search is slow).
I implemented in my own: Search by "car" then by "models" then merge but I'm interested if lucene can handle it.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t

INSERT INTO `recipe`(`Recipe_Id`, `Recipe_Name`, `Ingredients`, `Method`, `Servings`, `Ranking`) VALUES ([1],['Garlic Chicken'],['4 cloves garlic, chopped','1/2 cup any oil','1/4 cup bread crumbs','4 boneless, skinless chicken breasts''salt as required','black pepper as required'],['(if you have oven Preheat oven to 375 degrees F (190 degrees C))In small pan, stir fry garlic with the oil then mix chicken with garlic and black pepper and add garlic mixture on it and then coat them with bread crumbs then Bake in the preheated oven for 45 minutes to 1 hour. INCASE you donot have oven you can cook it in a sauce pan using 1 cup oil. cook untill it gets golden brown and then serve],[5],[0]);
I do not know where I am wrong. How can this be solved?
You are missing a closing quotation mark after serve. You syntax for the ingredients values is also wrong. It should be:
INSERT INTO recipe
( Recipe_Id ,
Recipe_Name ,
Ingredients ,
Method ,
Servings ,
Ranking
)
VALUES ( 1 ,
'Garlic Chicken' ,
'4 cloves garlic, chopped, 1/2 cup any oil, 1/4 cup bread crumbs, 4 boneless, skinless chicken breasts salt as required,black pepper as required' ,
'(if you have oven Preheat oven to 375 degrees F (190 degrees C))In small pan, stir fry garlic with the oil then mix chicken with garlic and black pepper and add garlic mixture on it and then coat them with bread crumbs then Bake in the preheated oven for 45 minutes to 1 hour. INCASE you donot have oven you can cook it in a sauce pan using 1 cup oil. cook untill it gets golden brown and then serve' ,
5 ,
0
);

Using Dojo's behavior functionality to recognize scrolling events

I'm not able to figure out how to assign a function to a scroll event in Dojo.
I have seen this other post about using dojo's connect, but I've been unable to get that to work, and even if I could, my project's using behaviours as much as possible, so I'm really trying to get that to work first...
The puzzling thing for me, is that I've looked around on dojo's website a bit, and the only references I've seen to scroll events just mention them as an aside. On http://dojotoolkit.org/reference-guide/1.9/quickstart/events.html#connecting-to-a-dom-event as an example, there's a list of events that can be connect-ed to, and scroll isn't on them. Mouse wheel up + down are, but that does not cover all possible actions that might lead to a scroll occurring.
I've used jQuery's scroll event before, and that was nice and simple. The fact that I'm having this much trouble figuring out the scroll event in Dojo bothers me a little.
This is what I've tried:
var myBehavior = {
window : {
scroll: function(e) {
console.log("i'm scrolling");
}
}
};
behavior.add(myBehavior);
behavior.apply();
That loads without any problems, but scrolling doesn't give me the console logging message.
I've also tried
dojo.connect(window,'scroll',this,function() {
console.log("scrolling away");
})
which I pretty much got from the linked post, and I didn't get the console logging message either.
I'm starting to wonder if I'm missing a key library?
The ones I have required that I think are more than necessary:
- dojo/_base/lang
- dojo/query
- dojo/_base/event
- dojo/on
- dojo/behaviour
- dojo/window
Does anybody have a suggestion for how I start registering these scrolling events in Dojo? Thank you
I created a jsfiddle demoing the usage of dojo/on for the window scroll event.
html:
<body>
<div style="height:1000px;">
Bacon ipsum dolor sit amet meatball drumstick jerky strip steak kielbasa shoulder, short ribs filet mignon prosciutto swine meatloaf ribeye tongue turkey andouille. Hamburger bacon fatback, short ribs pork loin cow chicken. Capicola venison andouille kielbasa cow. Short ribs kevin rump meatloaf jowl prosciutto leberkas. Pork belly shankle doner spare ribs, rump pork chop sausage tenderloin. Brisket swine pig, fatback beef ribs shank tri-tip flank ham venison strip steak filet mignon rump frankfurter ribeye.
Fatback turkey sausage tongue doner strip steak boudin shoulder chuck beef ribs chicken bacon brisket. Turkey biltong bacon cow short ribs fatback. Sausage brisket pork loin corned beef pork chop shank jowl capicola leberkas strip steak prosciutto beef tri-tip. Jowl frankfurter beef ribs, swine tail doner tri-tip t-bone. Jowl pork loin sausage venison salami shankle kevin strip steak boudin doner bresaola filet mignon ham drumstick ribeye. Turkey pork belly kielbasa ribeye salami, strip steak ham hock jerky shoulder tenderloin shankle spare ribs beef ribs filet mignon. Short loin fatback kevin, biltong tail shoulder ball tip.
Pork loin t-bone ground round tongue turducken tail shoulder chicken sausage pancetta hamburger, kielbasa tri-tip strip steak short ribs. Pork chop prosciutto tri-tip, jerky brisket leberkas andouille ham hock tongue shoulder fatback meatball. Pig short loin beef spare ribs, rump meatball short ribs doner kielbasa ball tip swine bacon kevin. Hamburger tail frankfurter ham hock tongue, jerky pork belly bacon shank salami prosciutto ground round doner jowl turducken. Prosciutto pork chop drumstick ham hock meatloaf. Drumstick ham hock ball tip salami cow.
Shankle hamburger sirloin sausage tongue pork chop flank, doner pig tri-tip pancetta shoulder. Venison ball tip beef biltong tail, corned beef pastrami andouille frankfurter kevin pork meatball chicken. Ground round shankle sirloin capicola kevin spare ribs ham hock fatback strip steak short ribs leberkas. Venison flank tenderloin tri-tip salami pork capicola drumstick brisket short ribs sirloin chuck boudin kielbasa cow.
Short ribs corned beef shankle meatball, tri-tip t-bone sirloin cow leberkas chicken jerky. Short loin drumstick pork loin biltong sausage prosciutto rump flank hamburger pork chop meatball capicola turkey leberkas cow. Andouille ribeye boudin ham chicken. T-bone rump meatball drumstick hamburger pork chop, flank sausage tongue andouille fatback.
Does your lorem ipsum text long for something a little meatier? Give our generator a try… it’s tasty!
</div>
</body>
js:
require(['dojo/on','dojo/domReady!'],function(on,domReadyPlugin){
on(window,'scroll',function(evt){
console.log(evt);
});
});
The result will print to the console every time the user scrolls in the window. If you continue to have issues with it, post more code so we can get to the bottom of it, this should be a simple thing to do.
use "onscroll" instead of "scroll", see this jsfiddle
dojo.connect(window,'onscroll',this,function() {
console.log("scrolling away");
})

HTML split a list in multiple columns

I'm trying to divide my list into multiple columns.
Example:
<ul class="loremipsum">
<li>Lorem ipsum 01</li>
<li>Lorem ipsum 02</li>
<li>Lorem ipsum 03</li>
<li>Lorem ipsum 04</li>
<li>Lorem ipsum 05</li>
<li>Lorem ipsum 06</li>
<li>Lorem ipsum 07</li>
<li>Lorem farem 08</li>
<li>Lorem ipsum 09</li>
<li>Lorem ipsum 10</li>
<li>Lorem ipsum 11</li>
<li>Lorem ipsum 12</li>
<li>Lorem ipsum 13</li>
<li>Lorem ipsum 14</li>
<li>Lorem ipsum 15</li>
<li>Lorem ipsum 16</li>
</ul>
Lorem ipsum 01 Lorem ipsum 06 Lorem ipsum 11 Lorem ipsum 16
Lorem ipsum 02 Lorem ipsum 07 Lorem ipsum 12 etc
Lorem ipsum 03 Lorem ipsum 08 Lorem ipsum 13
Lorem ipsum 04 Lorem ipsum 09 Lorem ipsum 14
Lorem ipsum 05 Lorem ipsum 10 Lorem ipsum 15
This is not a problem with jquery as I have found "Easy List Splitter".
However, this does not provide me with what I need.
The problem with the script of "Easy List Splitter" is that I need to put in an amount of columns. This is a problem for me because I'll be adding new items to this list weekly (if not daily) at the top of the list. It would mean I would need to edit the js file everytime.
Now that wouldn't even be a big problem (editting the amount of columns).
However, some of these list items (maybe 1 out of 10) is an image link.
What I would like to accomplish is this (numbers are just examples):
a wrapper div with 300px height
each list item has a min-height of 60px
max. 5 items per column
min. 1 item per column ofcourse
any column (left, right or the center) should be able to have only 1 list item if that 1 list item is 300px height for example (or 2 of 150px etc)
must be a vertical list
new column automatically created on the right of the other columns
A better question is........is this possible?
If new DIV's would show below/on top of eachother instead of next to eachother, the problem was solved already.
Big big thanks in advance!
If any more questions, please ask.
You might find some interest in this W3C recommendation about Multiple-Column layout which you can already use (with some prefixes though) on modern browsers.
Maybe not exactly what you would have wanted, but I think this is the best solution for your problem at the moment...
The nearest solution I found is to make LI float left and assign a width of 33% (for 3 columns) but it will not fill a column before starting another. The CSS Indeed is not complex.
.loremipsum li {
display: inline;
float: left;
width: 25%;
}
http://jsfiddle.net/cSJNm/

Resources