Class: Shi::Jekyll::Images::SVGFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Extended by:
Config
Includes:
Config
Defined in:
lib/shi/jekyll/images/files.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

config, get_value, path_by_page, site, site_config

Constructor Details

#initialize(path, source) ⇒ SVGFile

Returns a new instance of SVGFile.



208
209
210
211
212
# File 'lib/shi/jekyll/images/files.rb', line 208

def initialize path, source
  @wp_path = path
  @wp_source = source
  super site, site.source, File.dirname(path), File.basename(path)
end

Class Method Details

.create(page, source) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/shi/jekyll/images/files.rb', line 188

def create page, source
  return source if source.write?

  @@created ||= {}
  key = make_key source
  result = @@created[key]
  if result == nil
    result = new path(page, source), source
    @@created[key] = result
  end
  if !site.static_files.include?(result)
    site.static_files << result
  end
  result
end

.make_key(source) ⇒ Object



184
185
186
# File 'lib/shi/jekyll/images/files.rb', line 184

def make_key source
  Jekyll::PathManager::join '', source.relative_path
end

.path(page, source) ⇒ Object



180
181
182
# File 'lib/shi/jekyll/images/files.rb', line 180

def path page, source
  Jekyll::PathManager::join path_by_page(page), source.name
end

Instance Method Details

#modified?Boolean

Returns:

  • (Boolean)


214
215
216
217
218
219
# File 'lib/shi/jekyll/images/files.rb', line 214

def modified?
  src_path = File.join(site.source, @wp_source.relative_path)
  tgt_path = destination site.dest
  return true unless File.exist?(tgt_path) && File.exist?(src_path)
  File.mtime(src_path) > File.mtime(tgt_path)
end

#write(dest) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/shi/jekyll/images/files.rb', line 225

def write dest
  return true if !write?

  tgt_path = destination dest
  src_path = File::join site.source, @wp_source.relative_path

  return false unless File.exist?(src_path)

  FileUtils::mkdir_p(File.dirname(tgt_path))
  FileUtils::rm(tgt_path) if File.exist?(tgt_path)
  FileUtils::cp(src_path, tgt_path)

  true
end

#write?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/shi/jekyll/images/files.rb', line 221

def write?
  modified?
end