Middleman’s link_to helper for localized templates - middleman

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}

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.

Middleman and I18n: having some issues

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

Using gon with jasmine-rails

Our backbone app uses gon. When we try to run our tests, we are getting a gon is undefined error in the console of the browser. Our layout file includes a call to include_gon, but that file is not being loaded by jasmine, so jasmine is failing in our first javascript file that contains gon. We tried creating a helper to assign the gon variable to an empty hash (like a fixture), but the helper was called after the first call to gon and therefore didn't fix our issue.
The secret was to use the asset pipeline to define the load order of my files. I commented out these lines from jasmine.yml
# path to parent directory of src_files
# relative path from Rails.root
# defaults to app/assets/javascripts
#src_dir: "app/assets/javascripts"
# list of file expressions to include as source files
# relative path from src_dir
#src_files:
# - "application.{js.coffee,js,coffee}"
And created spec.js.coffee with these lines:
#= require application
#= require jasmine-jquery
Now my js files get loaded in order and I am good to go.
What worked for me was to define window.gon = {} inside the test like so:
describe("A suite is just a function", function() {
beforeEach(function() {
window.gon = {}
gon.test = "this"
})
it ("should find gon", function() {
expect(gon.test).toBe("this")
})
})

Prevent Yii from loading JS out of assets

Is there a way to configure Yii such that it will no longer load any Javascript out of the Assets folder?
Make your own AssetManager or extend current
protected/components/DummyAssetManager.php:
class DummyAssetManager extends CApplicationComponent {
public function publish(){}
}
add into components array in
protected/config/main.php:
'assetManager'=>array(
'class'=>'DummyAssetManager',
),
You should consult the manual for a detailed description of
the assetManager options
I think you can try following option in your config/main.php
'components' => array(
'assetManager' => array(
'linkAssets' => true,
),
),
This will make asset files symbolic links to your original js/css sources. See linkAssets for more details on it.
If your PHP<5.3, or the OS it's running on doesn't support symbolic links, you won't be able to use 'linkAssets' option, in this case you can try:
'components' => array(
'assetManager' => array(
'forceCopy' => true,
),
),
This should update asset folder on every request. These two options are usually used during development process (btw, you can't use both) and should be removed from production.
PS: if you're sure that you haven't explicitly enabled ckeditor somewhere in your code and you're confident about your assetmanager calls throughout the code, check your layout and page for widgets that require this CKeditor, as Yii can't preload 'stuff' just randomly, it can be triggered by some preloaded component/extension or yii widget.

How do you have a default Gravatar that is external and that actually resizes properly?

To implement Gravatar in my Rails3 application, I'm using the gravatar_image_tag gem in a helper, but I'm having issues when mixing 2 config options:
If the user doesn't have a gravatar attached to his email a default image is rendered; but I want it to reference an external file (e.g., http://www.iconfinder.com/ajax/download/png/?id=43350&s=128 instead of :identicon or others)
I also want the image to be resized on the fly to, let's say 50px.
Independently, both options work as expected, but when I put them together:
def gravatar_for(user, options = { :default => 'http://www.iconfinder.com/ajax/download/png/?id=43350&s=128', :size => 50 })
gravatar_image_tag(user.email.downcase, :alt => user.full_name,
:class => 'gravatar',
:gravatar => options)
end
the size option is not applied, and the gravatar gets rendered in it's full size (128px in this case).
What am I doing wrong, or how can I achieve this combination?
Gravatar will not resize your default image for you. I assume that it just 302s to the ulr gave as a default if it does not find an gravatar for the email you gave it. It looks like the 's' parameter in the iconfinder url is for the size you are trying to grab but that icon does not have a size of 50px available only 128, 256, and 512
Example:
http://www.iconfinder.com/ajax/download/png/?id=43350&s=256
If you wanted a 50px and 80px versions of the icon I would save it to your applications public/image directory as default_gravatar_50.png and default_gravatar_80.png respectively and change your method like so.
end
def gravatar_for(user, options = {})
options = { :size => 50 }.merge(options)
options[:default] = image_tag("default_gravatar_#{options[:size]}.png
gravatar_image_tag(user.email.downcase,
:alt => user.full_name,
:class => 'gravatar',
:gravatar => options)
end
Or if you find an icon on icon finder that is the size(s) you like change the setting of the default option like so.
options[:default] = "http://www.iconfinder.com/ajax/download/png/?id=43350&s=#{options[:size]}"
Iconfinder here. You don't want to link to the download script. Instead just grab the URL to the image it self so you wan't get a lot of header information.