Jade - way to add dynamic includes - express

I'd like to do something like the following within a jade template.
include page-content/#{view.template}
As this won't work I have ended up with.
-if(view.path==="/")
include ../page_content/home
-else if(view.path==="/login/")
include ../page_content/login
-else if(view.path==="/join/")
include ../page_content/join
-else if(view.path==="/user/")
include ../page_content/user
ad nauseum
I asked TJ whether it was possible, he replied
unfortunately no, they're compile-time includes, which is somewhat necessary for a few technical reasons that I wont get into but we may eventually need to add a dynamic alternative
I'm wondering if anyone has come up with any alternatives, for example using view helpers.
I'm stuck with a big config file to generate the views - and the if-else statements in the template , I know are going to come back and haunt me. :)
If this is possible using another engine, like ejs or mustache, I'd love to know.
Any ideas much appreciated.

Feels like way too much logic in the view to me. Seems like the best way to do this would be through a dynamicHelper or possibly a mixin

Related

Switch to the another language on the same page?

I am trying to add a language changer for Middleman and it's not generating the correct link. My default and root is English.
url_for("/#{current_page.path}", locale: :ja)
I would expect the equivalent for the current page in JA which is the same URL with JA prepended. Does anyone know how to fix this?
I'm a middleman beginner, but after doing a bunch of Googling it seems like this is a fairly common issue. I've tried to look through the middleman sources to see if I could find a solution, but I've been unable. I'm kinda disappointed about this, because it looks like middleman has first-class support for localizations. Being unable to easily link from one to another seems like a surprising omission.
What I've done is make a little helper that can swap localizations in paths, if needed.
def change_locale_in_path(path, locale)
locale_prefix = I18n.locale
path.gsub(/^#{locale_prefix}/, locale.to_s)
end
This isn't a great solution, though. It will need to be adjusted if you change the i18n :path, and won't work unless you mount_at_root: false. But, it worked well enough for me to move on. I really would love to see a better solution.
I found a few GitHub issues that seem to reference this problem. Here's one.
I am using the following helper to generate a URL for the current page in a different language. It was originally based on this gist, and then tweaked it a bit so that it works regardless of whether mount_at_root is used.
def current_url_for_locale(loc)
url_regex = /\A\/(?:(#{I18n.available_locales.join('|')})\/)?/
locale_root = url_for('/', locale: loc)
current_page.url.gsub(url_regex, '').blank? ?
locale_root :
current_page.url.gsub(url_regex, locale_root)
end

how to precompile, concat, minify, prefix, and zip scripts/stylesheets in expressjs?

I know I can use gruntjs but it seems it's suited for simple tasks and I can't figure out to embed more logic into it. Basically, I want to have if this and that for compiling. So i want there to be one main.css, and multiple sectionA.css. And when server starts it pre compiles everything to one.css for each section.
This is just one scenario I felt i couldn't make gruntjs do, I can see doing it but it just makes it populated it doesn't seem right way to do it.

Trimming the leading THE in SQL results on Joomla module Articles Category

I am trying to trim the leading "the" in a query that returns the titles of articles in Joomla, so that results are displayed in alphabetical order and the leading "the", if present, is disregarded. The module responsible for this is the Article Category (which is Joomla core module) and the file I think I should modify is helper.php in modules/mod_articles_category.
I replace the following line:
$articles->setState('list.direction', $params->get('article_ordering_direction',
'ASC'));
With this:
$articles->setState('list.direction', $params->get('article_ordering_direction',
'TRIM(LEADING \'THE \' FROM a.title) ASC'));
However, if I enable the debug mode, the TRIM is not showing. SO I guess, that I need to make the change somewhere else. Sorry but I am not familiar with Joomla so don't really know where this query is coming from. Any pointer is very much appreciated.
Okay, the short answer is no, I don't believe you can modify a query from a module, just like this. I haven't worked with modules, but I have some experience with components, so I would suggest two approaches:
Try to query the database yourself from the module, not by using setState, but building the query yourself.
You can cheat. Since Joomla has already done the heavy lifting for you, you could just manipulate the result object (i.e. $list) rearranging it and stripping off whatever you don't want. I would also suggest that you treat your code as a layout override, that way you'll be able to update your site without overriding the changes you have made.

confusion in using YII CHtml::link and CHtml::image instead of HTML

I have started an application in YII, I want to use proper standards of YII but am just bit curious about the use of its CHTML Class. I think that using CHtml::link() or CHtml::image() instead of normal HTML code <a></a> and <img src... /> will cost more time to application on server side. I tried to look for some reason to use it but yet not success in finding any good resource on why should I use it and how its beneficial then traditional HTML. Like I can use all those methods for defining paths to actions in normal HTML code then why use it
any help or reference for clarification would be appreciated
Thanks
Let's talk about CHtml::link(). Its main advantage is that you can indicate a controller route and send some get variables by simply passing an array as paramater. Lets say you wanna go to the eat() action of your LivingController, with the variable 'meal' and its value being 'hamburgers'. It could simply be done like this:
> CHtml::link(array('LivingController/eat', 'meal'=>'hamburgers'));
If you want to express this using <a></a> only, then I don't need to tell you how much harder it would be. In addition, we should remember that a link generated using CHtml::link() will always work, even if you change the url format. That wouldn't happen with <a></a>: you would have to rewrite the url every time you change the url format.
The advantages of CHtml::image() are less clear, at least to me. Sincerely, I think it's just a matter of encapsulation.

Accessing model attribute from css/less file with Rails 3

The project I'm working on requires me to adapt the size of the elements on screen according to per-user setting. We're using Twitter bootstrap, so my first idea was to toy with the #basefont value, and it seems to do the trick.
However, I don't know how to access the user setting from the .less file. I tried using erb with .less.erb, but it looks like I don't have access to any code in my application.
Is there a way to get the value I'm looking for from the .less file, or - even better - a proper way to do this ?
Thanks for your time.
EDIT
Since I need to get the value at runtime, the way I tried won't work anyway, though I'm still interested on an answer. The only way I see to do what I want is to add a class according to the user setting. Again, I'd be glad to have alternatives.
I opted for css3 transform (and vendors implementation) property. It does the job, but seems to hit the GPU quite a lot. So still open to other answers. :)