Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the ui element to select the languages for a site
- Loading branch information
Showing
19 changed files
with
265 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
module Locomotive::SitesHelper | ||
|
||
# def error_on_domain(site, name) | ||
# if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) }) | ||
# content_tag(:span, error, :class => 'inline-errors') | ||
# else | ||
# '' | ||
# end | ||
# end | ||
def ordered_current_site_locales | ||
current_site.locales + (Locomotive.config.site_locales - current_site.locales) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Locomotive | ||
class LocalesInput < ::Formtastic::Inputs::CheckBoxesInput | ||
|
||
def to_html | ||
input_wrapping do | ||
label_html << | ||
choices_group_wrapping do | ||
collection.map { |choice| | ||
choice_wrapping(choice_wrapping_html_options(choice)) do | ||
choice_html(choice) | ||
end | ||
}.join("\n").html_safe | ||
end | ||
end | ||
end | ||
|
||
def choices_group_wrapping(&block) | ||
template.content_tag(:div, | ||
template.capture(&block), | ||
choices_group_wrapping_html_options | ||
) | ||
end | ||
|
||
def choice_wrapping(html_options, &block) | ||
template.content_tag(:div, | ||
template.capture(&block), | ||
html_options | ||
) | ||
end | ||
|
||
def choice_html(choice) | ||
check_box_without_hidden_input(choice) << | ||
template.content_tag(:label, | ||
choice_label(choice), | ||
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil) | ||
) | ||
end | ||
|
||
def choice_label(choice) | ||
text = I18n.t("locomotive.my_account.edit.#{choice}") | ||
template.image_tag("locomotive/icons/flags/#{choice}.png", :alt => text) << text | ||
end | ||
|
||
def choices_group_wrapping_html_options | ||
{ :class => 'list' } | ||
end | ||
|
||
def choice_wrapping_html_options(choice) | ||
super.tap do |options| | ||
options[:class] = "entry #{checked?(choice) ? 'selected' : ''}" | ||
end | ||
end | ||
|
||
def hidden_fields? | ||
false | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Locomotive | ||
module Extensions | ||
module Site | ||
module I18n | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do | ||
|
||
## fields ## | ||
field :locales, :type => 'RawArray', :default => [] | ||
|
||
## callbacks ## | ||
# after_validation :add_missing_locales_for_all_pages | ||
|
||
end | ||
|
||
module InstanceMethods | ||
|
||
def locales=(array) | ||
array = [] if array.blank?; super(array) | ||
end | ||
|
||
def default_locale | ||
self.locales.first || Locomotive.config.site_locales.first | ||
end | ||
|
||
# protected | ||
# | ||
# def add_missing_locales_for_all_pages | ||
# if self.locales_changed? | ||
# list = self.pages.to_a | ||
# | ||
# while !list.empty? do | ||
# page = list.pop | ||
# begin | ||
# page.send(:set_slug_and_fullpath_for_all_locales, self.locales) | ||
# | ||
# page.save | ||
# | ||
# rescue TypeError => e | ||
# list.insert(0, page) | ||
# end | ||
# end | ||
# end | ||
# end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.