I would like to generate Rules DSL from the helper module. I have custom blog helper and i would like it to generate RSS feeds automatically so I don't have to specify any compile and routing rules in the Rules file as long as specific metadata is present.
So lets say I have my blog in news.erb and news\*.md directory. Erb file has blog configuration in its metadata section (number of articles to show, ordering etc..) In preprocessing I have create_blog function which generates \page\N depending on the metadata I have in news.erb. If this metadata includes rss: true section I would like the create_blog function to also register 2 aditional rules (if those are not previously defined) and 1 aditional file /feeds/news.xml:
compile /feeds\/.+/ do
filter :erb
end
route /feeds\/.+/ do
item.identifier.chop + '.xml'
end
I can generate the file all right, but in order to keep the site modularized I want to create those above rules in the create_blog itself. This allows me to later, if I want to remove the blog, just comment out the module and not change Rules file.
Related
I would like to write a generator plugin to add some post-like items to my blog. The items are supposed to appear in the blog index, but they have no page associated to them (you can't click on them).
I know I need something like
class QuoteGenerator < Generator
safe true
def generate(site)
# add a single post
site.posts << QuotePost.new(site, site.source, "Blub")
end
end
But what I don't understand is how to implement my Post subclass. I've found that other plugins (like this one to embed Flickr photos) write the data they want to a markdown+YAML file, and then reference this file:
class QuotePost < Post
def initialize(site, base, title)
# Nooo, I don't want to create a .md file for this
name = "2016-05-13-test.md"
dir = ""
# (write out .md file here)
super(site, base, dir, name)
end
end
But then, I would hardly need a Plugin in the first place. I could just generate the markdown files myself (with an external script).
What I'd like to do is to just set a couple of variables in my Post subclass, and have them available in the template for the blog index. How can I do that?
The case you've described looks to be unrelated to Post, since usual posts are file-based. Collections may be suitable, but again - that's not clear how you getting the content.
I'd suggest two major options:
Use _data/ to set an object list, where each item has the required properties if you can define them via a static JSON/CSV/etc file (or generate it once, to separate external data producer and jekyll visualization).
Use :pre_render hook and a plugin if you have to define the data via code -
your hook will also receive a payload hash as a second parameter which allows you full control over the variables that are available while rendering
Having your data in site.data variable allows you to iterate through items, render something or include a template and so on. Also there are plugins which generate new pages based on site's data.
The right answer depends on how you're getting the content, which markup you need and how those items will be used.
In my current extension template i need to include template from another extension.
If i write
{include uri="design:article/full.tpl"}
it will search in my current extension. How can i direct it to other extension? According to doc there is a name parameter. What should be value of name?
https://doc.ez.no/eZ-Publish/Technical-manual/3.8/Reference/Template-functions/Miscellaneous/include
The design part of the design:article/full.tpl is already supposed to do what you want. It will search a article/full.tpl template, starting from a templates folder within your design folder extension/myextension/design.
eZ Publish will use the following rules to find the good template :
First : determinate which designs are used for the siteaccess. See the [DesignSettings] block in your site.ini files
[DesignSettings]
SiteDesign=a_design_specific_or_not_to_your_siteaccess
AdditionalSiteDesignList[]=another_generic_design
AdditionalSiteDesignList[]=standard
AdditionalSiteDesignList[]=base
Then : determinate which extensions are offering a design. See the [ExtensionSettings] block in each extension's design.ini file (exemple of the extension/ezflow/settings/design.ini.append.php) :
[ExtensionSettings]
DesignExtensions[]=ezflow
Finally, eZ Publish looks for the template. The SiteDesign design will be tried first, and then all the AdditionalSiteDesignList designs from top to bottom. Once the template is found, the lookup stops, and this information is cached (even if your TemplaceCache / TemplateCompile / ... is disabled). Remember the cache part, every time you add a new template, meant to be overriding another one, you need to clear the cache.
So if we have only 2 extensions offering a design, say ezflow and mysite, eZ Publish will try the following paths :
extension/mysite/design/a_design_specific_or_not_to_your_siteaccess/templates/full/article.tpl
extension/mysite/design/another_generic_design/templates/full/article.tpl
extension/mysite/design/standard/templates/full/article.tpl
extension/mysite/design/base/templates/full/article.tpl
extension/ezflow/design/a_design_specific_or_not_to_your_siteaccess/templates/full/article.tpl
extension/ezflow/design/another_generic_design/templates/full/article.tpl
extension/ezflow/design/standard/templates/full/article.tpl
extension/ezflow/design/base/templates/full/article.tpl
design/a_design_specific_or_not_to_your_siteaccess/templates/full/article.tpl
design/another_generic_design/templates/full/article.tpl
design/standard/templates/full/article.tpl
design/base/templates/full/article.tpl
Note that I made the hypothesis that the mysite extension has a higher priority than ezflow. See in settings/override/site.ini.append.php :
[ExtensionSettings]
ActiveExtensions[]
ActiveExtensions[]=mysite
....
ActiveExtensions[]=ezflow
....
This is for the system templates. The process is a little different when it comes to content templates (the ones which are used by attribute_view_gui and node_view_gui functions), see https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Templates/The-template-override-system
I use KendoUI library in my project, so it's already minified but incredibly big.
Is it possible to exclude it from being uglified when using grunt-usemin?
Thanks!
In your grunt configuration, use an explanation point to make an exclude. Place those at the end of your src array.
e.g., add to the end of the src array, add:
'!htdocs/js/kendo.all.min.js'
You'll have to modify your flow for js and use a custom post-processor, which basically consists on adding a flow property to your useminPrepare.options (follow the basic structure in usemin README file), but instead of just adding a step (e.g. 'uglify'), plug a custom post-processor:
name: 'uglify',
createConfig: function (context, block) {
...
}
To customize how it will handle files, copy the createConfig from the example file you find most useful (see files in grunt-usemin/lib/config/) and modify it as you need (i.e. excluding the file you want).
I used a custom post-processor to add ngAnnotate to the usemin flow for js, just changing name to ngAnnotate and copying the createConfig from uglify).
I need to add additional translations to the Silverstripe 3 translation tables in sapphire/lang/[lang].yml
I am pulling in 'sapphire' as an SVN external so cannot just add the new values to the existing yml files.
Am I able to create additional language yml files for languages to add to these translations in mysite directory?
Yes, just create a new module with the following structure:
z_translations/
_config.php
lang/
en.yml
The z_ prefix ensures it comes alphabetically last, currently there's no way to influence loading order. the translations part can be anything. _config.php can be empty, but needs to be present for the folder to be detected as a module.
Note that in order to override translations in framework/admin/lang/, you have to create an admin subfolder in your module as well ... don't ask ;)
Every time a tpl file is included the system first looks for a site-specific version of the file and falls back to a standard one if the site specific one does not exist. So perahps I put include "customer/main/test1.tpl". If our site is google, the system would first look for "customer/main/google_test1.tpl" and fall back to "customer/main/test1.tpl" if that file doesn't exist.
Note: Smarty 2.6.x
Did you know about the built-in template directory cascade? addTemplateDir and setTemplateDir allow you to specify multiple directories:
$smarty->setTemplateDir(array(
'google' => 'my-templates/google/',
'default' => 'my-templates/default/',
));
$smarty->display('foobar.tpl');
Smarty will first try to find my-templates/google/foobar.tpl, if not found try my-templates/default/foobar.tpl. Using this, you can build a complete templating cascade.
That won't be too helpful if you have lots of elements on the same cascade-level. Say you had specific templates for google, yahoo and bing besides your default.tpl. A solution could involve the default template handler function. Whenever Smarty comes across a template it can't find, this callback is executed as a measure of last resort. It allows you to specify a template file (or template resource) to use as a fallback.
So you could {include}, {extend}, ->fetch(), ->display() site_google.tpl. If the file exists, everything is fine. If it doesn't, your callback could replace _google with _default to fallback to the default template.
If neither template_dir cascade nor default template handler function seems applicable, you'll want to dig into custom template resources.