Module: EvilFront::Helpers

Defined in:
lib/evil-front/helpers/tel.rb,
lib/evil-front/helpers/ruble.rb,
lib/evil-front/helpers/title.rb,
lib/evil-front/helpers/head_tag.rb,
lib/evil-front/helpers/title_tag.rb,
lib/evil-front/helpers/head_content.rb,
lib/evil-front/helpers/flying_quotes.rb,
lib/evil-front/helpers/standard_assets.rb,
lib/evil-front/helpers/capitalize_first.rb,
lib/evil-front/helpers/english_typograph.rb,
lib/evil-front/helpers/russian_typograph.rb,
lib/evil-front/helpers/auto_flying_quotes.rb,
lib/evil-front/helpers/disable_mobile_zoom.rb,
lib/evil-front/helpers/typograph_by_locale.rb

Instance Method Summary collapse

Instance Method Details

#auto_flying_quotes(text = nil, &block) ⇒ Object

Find quotes and add tags to flying quotes

= auto_flying_quotes post.body

Don’t forget to install styles by ‘quotes` Sass mixin.



7
8
9
10
11
12
13
14
15
# 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_first(text) ⇒ Object

Capitalize only first letter (like titles in Russian).

= capitalize_first post.title


5
6
7
# File 'lib/evil-front/helpers/capitalize_first.rb', line 5

def capitalize_first(text)
  EvilFront::Russian.capitalize_first(text)
end

#disable_mobile_zoomObject

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


8
9
10
11
12
# 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

#english_typograph(text = nil, &block) ⇒ Object

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


12
13
14
15
16
17
18
19
20
# 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

#flying_quotes(text = nil, options = { }, &block) ⇒ Object

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


11
12
13
14
15
16
17
18
19
# 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

#head_content(&block) ⇒ Object

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


7
8
9
# File 'lib/evil-front/helpers/head_content.rb', line 7

def head_content(&block)
  content_for(:evil_front_head, &block)
end

#head_tag(options = { }, &block) ⇒ Object

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


14
15
16
17
18
19
20
21
22
23
24
25
# 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

  (:head, head)
end

#rubleObject

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)


12
13
14
# File 'lib/evil-front/helpers/ruble.rb', line 12

def ruble
  EvilFront.html_safe('<span class="ruble">Р</span>')
end

#russian_typograph(text = nil, &block) ⇒ Object

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


12
13
14
15
16
17
18
19
20
# 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

#standard_assets(attributes = { }) ⇒ Object

Add ‘application.css`, jQuery from Google CDN and `application.js`.

html
  = head_tag do
    = standard_assets


7
8
9
10
11
12
# 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

#tel(number, args = { }) ⇒ Object

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')


7
8
9
10
11
# 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(' ')
  (:a, number, args)
end

#title(*titles) ⇒ Object

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


15
16
17
18
19
20
21
# 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

#title_tag(*site) ⇒ Object

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: ' * ')


19
20
21
22
23
24
25
26
27
28
29
# 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

#typograph_by_locale(text = nil, &block) ⇒ Object

Add typograph rules to text by language in current locale.

typograph_by_locale(post.body)


5
6
7
8
9
10
11
12
13
14
15
# 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