Middleman and I18n: having some issues - middleman

I have activated I18n in middleman like so:
activate :i18n, mount_at_root: :de
Now I'd like to be redirected from / to /de automatically. Is this possible?
Also, I wonder why middleman auto-assigns class index (for german) and en_index (for english) using the page_classes helper? This doesn't make much sense - it's the same page, so it should use the class index for both english and german. Or did I miss something?

If you :mount_at_root => :de german will be your default language and thus not prefixed.
If you set :mount_at_root => :false all languages should be prefixed.
I have successfully used the following configuration to set de/en paths.
This will also create page_classes such as as en en_index and de de_index.
activate :i18n, :mount_at_root => :false, :langs => [:de, :en]
http://middlemanapp.com/advanced/localization/
Redirecting from / to /de is done using redirect "index.html", :to => "de/index.html".
To prevent page_classes from prefixing the classes with the language, overwrite the helper like so:
helpers do
def page_classes(path=current_path.dup, options={})
super(path.sub(/^[a-z]{2}\//, ''), options)
end
end

Related

Yii The view file does not exist - where do mail layouts go

I am using basic template but have adapted the advanced user password reset functionality, for some reason I can't get it to find the mail layouts.
So in \mail\layouts I have
- passwordResetToken-html.php
- passwordResteToken-text.php
In web.php I have
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => 'app\mail\layouts',
...
The advanced template uses
'viewPath' => '#common/mail',
But as i'm using basic template, its not in the common/mail folder.
In sendMail function in PasswordResetRequestForm.php i have
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
...
However getting error
The view file does not exist: app\mail\layouts\passwordResetToken-html.php
I know this is going to be something small but for the life of me i cannot see it
Removed the 'viewPath' of config, as the doc don't use it.
So it works.

Extending Laravel 5.1 Mess Detection the right way

Laravel 5.1 has only one built-in hardcoded Mess Detection, it searches to see if #package tag is the same with /namespace, like so:
preg_match('/namespace\ ' . self::REQUIRED_NAMESPACE . '\\\(.*);/isU', $content, $namespace);
preg_match('/\/*( )+#package\ (.*)[\r?\n]/isU', $content, $package);
if (!isset($namespace[1]) || empty($namespace[1])) {
continue;
}
I want to extend this to add multiple detection classes.
My folder structure currently looks like this:
Helpers >
Commands >
MessDetector >
Detector >
DetectorInterface.php
DetectorAbstract.php
PackageTagDetector.php
MessDetector.php
The file MessDetector is made as an Artisan Command, that means it extends \Illuminate\Console\Command
I have a config file called mess_detection.php which has the detection rules like so:
return [
'rules' => [
'\Helpers\Commands\MessDetector\PackageTagDetector' =>
[
'rule' => '/\/*( )+#package\ (.*)[\r?\n]/isU',
'path' => app_path(),
'info' => 'Checking for #package tag',
'error'=> 'Malformed or missing package tag'
]
]
];
But got stuck with figuring out how exactly to instantiate PackageTagDetector class in MessDetector class.
Any ideas design pattern wise?
Laravel has no built in mess detector.
Also checking if package tags matches the namespace is a custom convention, Laravel doesn't use package tags at all.
It seems like you are using a third party library?
I have made an abstract class and interfaces for every rule I needed.
Each rule had it's own class.
The rules extended the abstract and in the abstract most of the logic was used.
The rules themselves where stored in a config file, in the config file I also mentioned the class and class specific actions.

Middleman’s link_to helper for localized templates

For the site I'm building with Middleman, I am localizing entire templates as described in the docs on the bottom of the "Localization" section. So the relevant part of the file tree looks like this:
/localizable
|
|- index.en.html.haml
|- index.ru.html.haml
|- about.en.html.haml
|- about.ru.html.haml
I can link from the index.en page to the about.en page using the path helper like so:
= link_to 'about me', '/about.html'
But when I try to do a similar trick to create a link from the index.ru page to the about.ru page:
= link_to 'some russian text', '/russian/about.html'
the helper doesn't work. It ignores the /russian folder and creates a link to /about.html in root.
Am I missing something or is the path helper unusable for localized templates? Is the only option to use the <a> tag directly?
============
Update1: relevant parts of my config.ru file:
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
activate :relative_assets
set :relative_links, true
activate :i18n, :langs => [:en, :ru], :lang_map => { :en => :english, :ru => :russian }
activate :blog do |blog|
blog.prefix = "blog"
blog.paginate = true
end
# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
# activate :minify_css
# Minify Javascript on build
# activate :minify_javascript
# Enable cache buster
# activate :asset_hash
# Use relative URLs
# activate :relative_assets
# Or use a different image path
# set :http_prefix, "/Content/images/"
end
Cant really say what is the problem without seeing your config.rb file and the structure of your file system.
My guess on your problem would be like this here
or it could be real simple that you have to change 'russian' to 'ru', since that is in file name.
Here is a good example
EDIT:
Now with your config.rb , I can see you are using :en as default and :ru as russian
Since you are using :en as default(non prefixed), you dont have to map that. or if you want that to be mapped and not be default you might have to use ':mount_at_root => false' with activate 'activate :i18n,'
Try the following solution
activate :i18n, :langs => [:en,:ru], :lang_map => {:ru => :russian}
Like I said, I simply just removed :en mapping and it worked on my test. Since you make :en as default you dont have to map it. If you want both languages to be mapped correctly then use the following
activate :i18n, :mount_at_root => false, :langs => [:en,:ru], :lang_map => {:en => :english ,:ru => :russian}

Rails 3: mixing "generic" controller routes with standard resource routes

I've got a set of routes that looks like this:
resources :placements do
match '/foo' => "placements#foo"
match '/bar' => "placements#bar"
end
This produces routes that behave like you would expect:
/placements/1234/foo
/placements/1234/bar
However, I also need "generic" routes for a few methods that do not need an individual placement. So, I build a routes block that looks like this:
resources :placements do
match '/foo' => "placements#foo"
match '/bar' => "placements#bar"
end
match '/placements/baz' => "placements#baz"
If I rake routes, I get a route that looks good:
/placements/baz
Note the lack of an id. However, if I try to visit that route, Rails tries to call the show method on the controller instead, as if "baz" was an ID, instead of a method name. How can I build a routing structure that gives me what I am after, without having to change the first segment of my route (placements), to something else?
Move the second route over the resources block ie,
match '/placements/baz' => "placements#baz"
resources :placements, :id => /\d+/ do
match '/foo' => "placements#foo"
match '/bar' => "placements#bar"
end
or add a regex for the id in resources, ie something like:
resources :placements, :id => /\d+/ do
match '/foo' => "placements#foo"
match '/bar' => "placements#bar"
end
match '/placements/baz' => "placements#baz"

action mailer and url generation in Rails 3.0.9

So I realize that Rails mailers need help in generating urls. I want HTML email with images served externally (no attachments) so I've set both:
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.action_mailer.asset_host = "http://localhost:3000
and two things happen in my mailer template:
It hates the use of image_tag. Just barfs with an action view template error
url_for does nothing for unnamed routes. shouldn't it prepend the asset_host? for assets in public?