Class: Esvg::Svg
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#vesion ⇒ Object
readonly
Returns the value of attribute vesion.
Instance Method Summary collapse
- #embed ⇒ Object
- #id ⇒ Object
-
#initialize(name, symbols, config = {}) ⇒ Svg
constructor
A new instance of Svg.
- #named?(names = []) ⇒ Boolean
- #path ⇒ Object
Methods included from Utils
#attributes, #compress, #dasherize, #sort, #sub_path
Constructor Details
#initialize(name, symbols, config = {}) ⇒ Svg
10 11 12 13 14 15 16 17 |
# File 'lib/esvg/svg.rb', line 10 def initialize(name, symbols, config={}) @name = name @config = config @symbols = symbols @symbol_defs = [] @asset = File.basename(name).start_with?('_') @version = @config[:version] || Digest::MD5.hexdigest(symbols.map(&:mtime).join) end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
8 9 10 |
# File 'lib/esvg/svg.rb', line 8 def asset @asset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/esvg/svg.rb', line 8 def name @name end |
#vesion ⇒ Object (readonly)
Returns the value of attribute vesion.
8 9 10 |
# File 'lib/esvg/svg.rb', line 8 def vesion @vesion end |
Instance Method Details
#embed ⇒ Object
19 20 21 22 23 |
# File 'lib/esvg/svg.rb', line 19 def %Q{if (!document.querySelector('#esvg-#{id}')) { document.querySelector('body').insertAdjacentHTML('afterbegin', '#{svg}') }} end |
#id ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/esvg/svg.rb', line 31 def id if @name == '.' 'symbols' else dasherize "#{@config[:prefix]}-#{name_key}" end end |
#named?(names = []) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/esvg/svg.rb', line 25 def named?(names=[]) [names].flatten.map { |n| dasherize(n) }.include? dasherize(@name) end |
#path ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/esvg/svg.rb', line 39 def path @path ||= begin name = name_key if name.start_with?('_') # Is it an asset? File.join @config[:assets], "#{name}.js" else # or a build file? # User doesn't want a fingerprinted build file and hasn't set a version if !@config[:fingerprint] && !@config[:version] File.join @config[:build], "#{name}.js" else File.join @config[:build], "#{name}-#{@version}.js" end end end end |