Merge items in nanoc - ruby

I have been trying to use nanoc for generating a static website. I need to organize a complex arrangement pages I want to keep my content DRY.
How does the concept of includes or merges work within the nanoc system? I have read the docs but I can't seem to find what I want.
For example: how can I take two partial content items and merge them together into a new content item.
In staticmatic you can do some like the following inside your page.
= partial('partials/shared/navigation')
How would a similar convention work within nanoc?

nanoc’s author here.
In nanoc, partials are layouts. So, you could have layouts/partials/shared/navigation.html and then render that partial like this:
= render '/partials/shared/navigation'
For that to work, enable the Rendering helper first, by including it somewhere in the lib/ dir (e.g. lib/helpers.rb):
include Nanoc3::Helpers::Rendering
For more information, check out the layouts as partials section of the manual.
Hope this helps!

Related

Can somebody give me an eagle eye perspective on Magento blocks, layout and templates?

Can somebody give me an eagle eye perspective on Magento blocks, layout and templates and how they relate to each other?
I understood that blocks are the basic building-blocks that a page is made of and that they are kind of mini-controllers.
I also understood that layout brings these blocks somehow together.
But there is still some uncertainty about templates and how they relate to blocks and layouts and vice versa.
What are blocks?
There are basically 4 things you need to know:
There are two types of blocks: those that automatically render their
children and those that don't. Knowing which type you're using will
help you in debugging.
Magento blocks are essentially models that contain logic for your view templates. Mind you - this is not business logic, but it is logic
related to the display of the information you're presenting. This is
by definition presentational logic. If you're familiar with Zend
Framework's Zend_Layout you could draw a comparison between custom
view objects and layout helpers.
The template file assigned to a block object can execute code as if it is local to that object. That is, $this corresponds directly to
the block class.
Layout actions are a thing that people use.
Two types of blocks
There are two types of blocks at the end of the day - those that
render automatically and those that don't. Take notes because this is
on the Magento Certification exam!!
Auto-rendered blocks
When defined in a layout, any block of type core/text_list will
automatically render all its children. While core/text will
automatically render itself it really only should contain text and
therefore is not useful for layout purposes (though some clever things
can be achieved with them).
Other blocks
Any other block type will need to be rendered manually. Provide the
block an alias which can then be passed to getChildHtml, returning the
content which you then echo.
Layouts And Templates
As the name suggests, layout files are useful in rendering front pages
of Magento. Layout files are XML files that reside in in app > design
frontend > your interface > your theme > layout. Here, you can see that there are many layout files for any given module. Each Magento
module has its own layout files much like the customer module has the
customer.xml layout file, catalog module have catalog.xml layout file
etc. These layout files contain structural blocks and content blocks.
read the following blogs. it will clear your concepts for magneto.
http://alanstorm.com/category/magento
http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-4.html
http://blog.philwinkle.com/the-most-misunderstood-concept-in-magento/
http://code.tutsplus.com/tutorials/custom-layouts-and-templates-with-magento--cms-21419
Blocks are the building modules of a page. They can be treated as "bricks". Now every block comes inside a layout. Layout is used to define the "shape" of the page. Now templates are used to define the behaviour of a particular block. That means each block or "brick" will have different charateristic depend upon the template it is used.
That is, to construct a magento page, you need to define a layout first that will give you an idea of shape of that page. Now you fill the layout with blocks. Each blocks now concentrate on a particular section of the entire layout. That means depending upon the "nature" of block, each small section will behave differently. To define the unique nature of a particular section, blocks uses templates (templates actually holds the webpage building codes, ie html + js + php)
I hope that will give you a short idea.
Try to google this. I am sure there are lot of lot of tutorials, blogs available about this.

Localized partials in Middleman

In Middleman, is it possible to localize partials? I haven't been able to find any documentation for this. But I'm working on long pieces with complex markup, and it may be necessary to adjust the templates themselves for localization. I'd like to be able to narrow these sections down to partials so that I don't have to fall back on maintaining entirely separate templates when this happens. Is there a place I can put partials such that the partial command will look up a partial as partial_name.language.html.erb?
It might also be possible to dynamically construct partials argument if it's possible to tell what language I'm in within the ERb. So I could do something like <%= partial "my_piece/partials/#{current_lang}/tricky_section" %>, but I don't know if something like current_lang exists.
On the issue tracker, I found documentation of how I can use the second option I can do <%= partial "partials/my_piece/#{lang}/tricky_section" %>, or directly embed logic that otherwise keys off of lang.

Passing Markdown Content to Ruby Function With Jekyll/Liquid

I am trying to write a jekyll plugin that will take a normal markdown file and provide some extra functionality on top of it. In particular, I need to do some (not actually) fancy things with tables. I know you can write straight HTML into a markdown file, but there is a requirement that the content folks don't want to / can't edit HTML.
As an extra wrench in the works, the mobile layout has a UX requirement that I essentially have to render the table as a group of divs as opposed to a table.
My initial thought was to pass the {{page.content}} variable to a ruby function extending Liquid::Tag. From there I was planning on parsing the markdown file and either:
1. If normal non-table markdown, use as normal
2. If table markdown, look for custom identifier in markdown, do what needs to be done (e.g. add class, etc)
If I do something like this:
def render(context)
content = Liquid::Template.parse(#markup).render context
end
It renders the context as a normal markdown file. However, I want to break up the context variable and work with the pieces before rendering. I've tried a few different approaches that I've gotten from the jekyll docs and Stack Overflow and gotten nowhere.
Does anyone have any experience with this? I am heading down the right path? For what it's worth, Ruby/Jekyll/Liquid is fairly new to me, so if you think I may have missed something fairly basic and obvious then please let me know.
A markdown table tool for editors !
markdownify your table in http://www.tablesgenerator.com/markdown_tables
paste the markdown result in http://prose.io/
done
I don't know other way to simplify editor's work on Jekyll, but I'll be very interested in earing from your project. Good luck.

a rails partial but used by multiple views

I have a piece of code that I would like to have show up on several areas... from two different views. Which is to say handled by two different controllers (all the data comes from a helper though) what is the best way to break this up, should these partials be rendered then as lay outs? Though they use the twitter bootstrap modal and I have had huge issues getting those to show correctly when called from a layout (most the reason why I have to break up this code into a partial, one that comes from one index.erb.html and another that comes from a partial of its own _document_header.erb.html good time to ask, can you stuff one partial within another...
so just trying to get some pointers. This code is really common to two views.
(and is not always needing to be rendered or displayed)...so want to do this the best way.
You can reference a partial that is anywhere in your views folder.
It's common to make a "shared" folder in your views and reference the partial like: <%= render 'shared/my_partial' %>

magento - include core functionality in custom module

I've recently made my first couple of simple modules for magento. Basically just trying out making a module that printed 'hi'. Then one that included the site design, and finally one that inserted it's own block into the content area to print some stuff.
Now, what I really want with this module is to be able to list products (using the same layout as normal product listing) but based on ID's. Like from cookies or as an example, static array of product ID's.
How would I go about to reuse the product listing code as much as possible and retaining the theming for it? Also if there is some small detail I wanted to change in the layout - how could i make a small template adjustment on the fly/programmatically?
Is this even the right way to go about it, to create a new module and somehow include existing functionality in it? Or should I just try to recreate the product listing and mimic the design?
Lots of questions I know, but it's hard to find relevant information beyond the very simplest modules. TIA.

Resources