Module: Dekiru::Helper
- Defined in:
- lib/dekiru/helper.rb
Instance Method Summary collapse
- #facebook_like(url = url_for(only_path: false), app_id = nil, width = 140) ⇒ Object
- #google_analytics(code, options = {}) ⇒ Object
- #google_plus ⇒ Object
- #menu_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #null_check_localization(*args) ⇒ Object (also: #nl)
- #twitter_tweet ⇒ Object
Instance Method Details
#facebook_like(url = url_for(only_path: false), app_id = nil, width = 140) ⇒ Object
27 28 29 30 31 |
# File 'lib/dekiru/helper.rb', line 27 def facebook_like(url = url_for(only_path: false), app_id = nil, width = 140) facebook_app_id = app_id || ENV['FACEBOOK_APP_ID'] html = %Q(<iframe src="//www.facebook.com/plugins/like.php?href=#{u(url)}&send=false&layout=button_count&width=140&show_faces=false&action=like&colorscheme=light&font=arial&height=21&appId=#{facebook_app_id}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:#{width}px; height:21px;" allowTransparency="true"></iframe>) html.html_safe end |
#google_analytics(code, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dekiru/helper.rb', line 49 def google_analytics(code, = {}) if code.present? && ::Rails.env == 'production' multi_subdomain = if [:domain] "_gaq.push(['_setDomainName', '#{[:domain]}']);" end html = <<-EOF <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '#{code}']); #{multi_subdomain} _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> EOF html.html_safe end end |
#google_plus ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/dekiru/helper.rb', line 41 def google_plus html = <<-EOF <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <g:plusone size="medium"></g:plusone> EOF html.html_safe end |
#menu_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dekiru/helper.rb', line 3 def (name = nil, = nil, = nil, &block) args = [name, , ] , , name = , name, block if block_given? classes = .try(:delete, :li_class).try(:split, ' ') || [] classes << 'active' if current_page?() obj = [].flatten.last if obj.is_a?(ActiveRecord::Base) content_tag_for(:li, obj, :class => classes.join(' ')) do link_to name, , , &block end else content_tag(:li, :class => classes.join(' ')) do link_to *args, &block end end end |
#null_check_localization(*args) ⇒ Object Also known as: nl
22 23 24 |
# File 'lib/dekiru/helper.rb', line 22 def null_check_localization(*args) localize(*args) if args.try(:first).present? end |
#twitter_tweet ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/dekiru/helper.rb', line 33 def twitter_tweet html = <<-EOF <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> EOF html.html_safe end |