module EvilFront::Helpers
Public Instance Methods
Find quotes and add tags to flying quotes
= auto_flying_quotes post.body
Don’t forget to install styles by `quotes` Sass mixin.
# File lib/evil-front/helpers/auto_flying_quotes.rb, line 7 def auto_flying_quotes(text = nil, &block) text = if block_given? capture(&block).strip else EvilFront.escape(text) end text = EvilFront::Russian.auto_flying_quotes(text) EvilFront.html_safe(text) end
Capitalize only first letter (like titles in Russian
).
= capitalize_first post.title
# File lib/evil-front/helpers/capitalize_first.rb, line 5 def capitalize_first(text) EvilFront::Russian.capitalize_first(text) end
Disable user zoom in mobile browsers. You should use it only if your styles are special optimized for mobile screens.
html head = disable_mobile_zoom
# File lib/evil-front/helpers/disable_mobile_zoom.rb, line 8 def disable_mobile_zoom html = '<meta name="viewport" content="width=device-width, ' + 'initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />' EvilFront.html_safe(html) end
Insert non-break spaces and mark quotes to have nice text. Work only with English
language.
= english_typograph user.description
You can send block:
= english_typograph do = user.name = user.profession
# File lib/evil-front/helpers/english_typograph.rb, line 12 def english_typograph(text = nil, &block) text = if block_given? capture(&block) else EvilFront.escape(text) end text = EvilFront::English.typograph_html(text) EvilFront.html_safe(text) end
Mark quotes to move first quote before the text line.
= flying_quotes feedback.text
You can send block:
= flying_quotes do a href=course.url = course.name
# File lib/evil-front/helpers/flying_quotes.rb, line 11 def flying_quotes(text = nil, options = { }, &block) text = if block_given? capture(&block).strip else EvilFront.escape(text) end text = EvilFront::Russian.flying_quotes(text, options) EvilFront.html_safe(text) end
Add content to head tag. Will be useful in page views.
- head_content do meta name="description" content=page.seo.description meta name="keywords" content=page.seo.keywords
# File lib/evil-front/helpers/head_content.rb, line 7 def head_content(&block) content_for(:evil_front_head, &block) end
Add content from `head_content` and statistics counter in production, if you set `:stats` option.
html head = head_tag do = title_tag(t.title) = standard_assets
You can disable statistics counter by options:
= head_tag(statistics: false) do
# File lib/evil-front/helpers/head_tag.rb, line 14 def head_tag(options = { }, &block) head = tag(:meta, charset: 'UTF-8') head += capture(&block) if block_given? head += content_for(:evil_front_head) options[:statistics] = true unless options.has_key? :statistics if options[:statistics] and Rails.env.production? head += render('layouts/statistics') rescue '' end content_tag(:head, head) end
Insert symbol of Russian
currency.
= order.price = ruble
Don’t forget to import ruble’s fonts and class in you Sass:
+import-ruble("PT Sans, sans-serif", $regular: inline)
# File lib/evil-front/helpers/ruble.rb, line 12 def ruble EvilFront.html_safe('<span class="ruble">Р</span>') end
Insert non-break spaces and mark quotes to have nice text. Work only with Russian
language.
= russian_typograph user.description
You can send block:
= russian_typograph do = user.name = user.profession
# File lib/evil-front/helpers/russian_typograph.rb, line 12 def russian_typograph(text = nil, &block) text = if block_given? capture(&block) else EvilFront.escape(text) end text = EvilFront::Russian.typograph_html(text) EvilFront.html_safe(text) end
Add `application.css`, jQuery from Google CDN and `application.js`.
html = head_tag do = standard_assets
# File lib/evil-front/helpers/standard_assets.rb, line 7 def standard_assets(attributes = { }) stylesheet_link_tag('application', media: 'all') + include_jquery(attributes.dup) + content_for(:evil_libraries) + javascript_include_tag('application', attributes) end
Render link with phone number. It will remove all non-digits symbols from phone number and format `tel:` protocol URI.
label Contact us: = tel('+7 (495) 660−83−79')
# File lib/evil-front/helpers/tel.rb, line 7 def tel(number, args = { }) args[:href] = "tel:" + number.gsub(/[^\d\+]/, '') args[:class] = (['tel', args[:class]]).compact.join(' ') content_tag(:a, number, args) end
Add page title. Will be used with site title in document title tag by `title_tag`.
- title 'FAQ'
You can set subtitles (order will be reversed):
- title 'FAQ', 'Ask'
By default `title_tag` will add site name to page title. You can show only page title by `no_site` option:
- title 'Site Home', no_site: true
# File lib/evil-front/helpers/title.rb, line 15 def title(*titles) options = titles.extract_options! @evil_front_no_site_in_title = true if options[:no_site] @evil_front_titles ||= [] @evil_front_titles += titles end
Return title tag with current page title. It will just join page titles from `title` helper and `site` name.
By default, separator will be m-dash for Russian
and n-dash for others.
html head = title_tag('Foo Company')
Separator will be taken by current locale. But, you can change it by `separator` option:
= title_tag('Foo Company', separator: ' * ')
# File lib/evil-front/helpers/title_tag.rb, line 19 def title_tag(*site) options = site.extract_options! separator = options[:separator] || (I18n.locale == :ru ? ' — ' : ' - ') site = [] if @evil_front_no_site_in_title @evil_front_titles ||= [] titles = (@evil_front_titles + site).compact titles = titles.join(separator) EvilFront.html_safe("<title>#{ EvilFront.escape(titles) }</title>") end
Add typograph rules to text by language in current locale.
typograph_by_locale(post.body)
# File lib/evil-front/helpers/typograph_by_locale.rb, line 5 def typograph_by_locale(text = nil, &block) text = capture(&block) if block_given? if I18n.locale == :ru russian_typograph(text) elsif I18n.locale == :en english_typograph(text) else text end end