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
- #config ⇒ Object
- #embed ⇒ Object
- #id ⇒ Object
-
#initialize(name, symbols, parent) ⇒ 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, parent) ⇒ Svg
Returns a new instance of Svg.
10 11 12 13 14 15 16 17 |
# File 'lib/esvg/svg.rb', line 10 def initialize(name, symbols, parent) @parent = parent @name = name @symbols = symbols @symbol_defs = [] @asset = File.basename(name).start_with?('_') @version = parent.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
#config ⇒ Object
25 26 27 |
# File 'lib/esvg/svg.rb', line 25 def config @parent.config end |
#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
35 36 37 38 39 40 41 |
# File 'lib/esvg/svg.rb', line 35 def id if @name == '.' 'symbols' else dasherize "#{config[:prefix]}-#{name_key}" end end |
#named?(names = []) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/esvg/svg.rb', line 29 def named?(names=[]) [names].flatten.map { |n| dasherize(n) }.include? dasherize(@name) end |
#path ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/esvg/svg.rb', line 43 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 |