Class: GoogleWebfonts::ConfigRenderer
- Inherits:
-
Object
- Object
- GoogleWebfonts::ConfigRenderer
- Defined in:
- lib/google-webfonts/config_renderer.rb
Instance Method Summary collapse
- #ascender=(options) ⇒ Object
- #custom=(options) ⇒ Object
- #fontdeck=(id) ⇒ Object
- #google=(families) ⇒ Object
-
#initialize ⇒ ConfigRenderer
constructor
A new instance of ConfigRenderer.
- #monotype=(id) ⇒ Object
- #render ⇒ Object
- #typekit=(id) ⇒ Object
Constructor Details
#initialize ⇒ ConfigRenderer
Returns a new instance of ConfigRenderer.
3 4 5 |
# File 'lib/google-webfonts/config_renderer.rb', line 3 def initialize @config = {} end |
Instance Method Details
#ascender=(options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/google-webfonts/config_renderer.rb', line 30 def ascender= return if .nil? raise ArgumentError, "expected a Hash, got a #{.class}" unless .class == Hash return if .empty? families = .values.first families = [families] unless families.is_a?(Array) @config.merge!({ ascender: { key: .keys.first.to_s, families: families } }) end |
#custom=(options) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/google-webfonts/config_renderer.rb', line 66 def custom= return if .nil? raise ArgumentError, "expected a Hash, got a #{.class}" unless .class == Hash return if .empty? families, urls = [], [] .each do |k, v| families << k.to_s urls << v end @config.merge!({ custom: { families: families, urls: urls, } }) end |
#fontdeck=(id) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/google-webfonts/config_renderer.rb', line 56 def fontdeck= id return if id.nil? @config.merge!({ fontdeck: { id: id } }) end |
#google=(families) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/google-webfonts/config_renderer.rb', line 7 def google= families return if families.nil? families = [families] unless families.is_a?(Array) return if families.empty? @config.merge!({ google: { families: families } }) end |
#monotype=(id) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/google-webfonts/config_renderer.rb', line 46 def monotype= id return if id.nil? @config.merge!({ monotype: { projectId: id } }) end |
#render ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/google-webfonts/config_renderer.rb', line 86 def render return "" if @config.empty? <<-JAVASCRIPT WebFontConfig = { #{hash_to_js(@config, 2)} }; JAVASCRIPT end |
#typekit=(id) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/google-webfonts/config_renderer.rb', line 20 def typekit= id return if id.nil? @config.merge!({ typekit: { id: id } }) end |