Class: Inkcite::Renderer::Social
- Defined in:
- lib/inkcite/renderer/social.rb
Defined Under Namespace
Classes: Facebook, Pintrest, Twitter
Constant Summary
Constants inherited from Base
Base::BACKGROUND_COLOR, Base::BACKGROUND_GRADIENT, Base::BACKGROUND_IMAGE, Base::BACKGROUND_POSITION, Base::BACKGROUND_REPEAT, Base::BACKGROUND_SIZE, Base::BORDER_BOTTOM, Base::BORDER_COLLAPSE, Base::BORDER_LEFT, Base::BORDER_RADIUS, Base::BORDER_RIGHT, Base::BORDER_SPACING, Base::BORDER_TOP, Base::BOX_SHADOW, Base::DIMENSIONS, Base::DIRECTIONS, Base::FONT_FAMILY, Base::FONT_SIZE, Base::FONT_WEIGHT, Base::LETTER_SPACING, Base::LINE_HEIGHT, Base::LINK_COLOR, Base::MARGIN, Base::MARGIN_BOTTOM, Base::MARGIN_LEFT, Base::MARGIN_RIGHT, Base::MARGIN_TOP, Base::MAX_WIDTH, Base::NONE, Base::PADDING_X, Base::PADDING_Y, Base::POUND_SIGN, Base::TEXT_ALIGN, Base::TEXT_DECORATION, Base::TEXT_SHADOW, Base::TEXT_SHADOW_BLUR, Base::TEXT_SHADOW_OFFSET, Base::VERTICAL_ALIGN, Base::WEBKIT_ANIMATION, Base::WHITE_SPACE, Base::ZERO_WIDTH_NON_BREAKING_SPACE, Base::ZERO_WIDTH_SPACE
Instance Method Summary collapse
-
#initialize(defaults) ⇒ Social
constructor
A new instance of Social.
- #render(tag, opts, ctx) ⇒ Object
Constructor Details
#initialize(defaults) ⇒ Social
51 52 53 54 55 56 57 58 |
# File 'lib/inkcite/renderer/social.rb', line 51 def initialize defaults @defaults = defaults # Ensure a default scale of 1:1 is installed into the defaults # if one is not otherwise provided. @defaults[:scale] ||= 1.0 end |
Instance Method Details
#render(tag, opts, ctx) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/inkcite/renderer/social.rb', line 60 def render tag, opts, ctx id = opts[:id] share_url = opts.delete(:href).to_s ctx.error("Social sharing 'href' attribute can't be blank", :tag => tag, :id => id) if share_url.blank? share_text = opts.delete(:text).to_s ctx.error("Social sharing 'text' attribute can't be blank", :tag => tag, :id => id, :href => share_url) if share_text.blank? # Let the extending class format the fully-qualified URL to the sharing service. service_href = get_share_href Util.escape(share_url), Util.escape(share_text), opts, ctx # Check to see if there is a special color for this link (e.g. Pintrest) or # if it has been specified by the caller. opts[:color] ||= @defaults[:color] if icon = !opts[:noicon] # Ensure that the sharing icon exists in the project. ensure_icon_exists ctx height = (opts.delete(:size) || opts.delete(:height) || 15).to_i width = (height / @defaults[:scale]).round # Force the font size and line height to match the size of the # icon being used - this ensures proper vertical middle alignment. opts[FONT_SIZE] = height opts[LINE_HEIGHT] = height end cta = opts[:cta] || @defaults[:cta] html = %Q({a href="#{service_href}" #{Renderer.join_hash(opts)}}) html << %Q({img src=#{@defaults[:src]} height=#{height} width=#{width} display=inline alt="#{@defaults[:alt]}"} ) if icon html << %Q(#{cta}{/a}) html end |