Class: EnhanceMetaData::Generator

Inherits:
Jekyll::Generator show all
Defined in:
lib/jekyll-emd-generator.rb,
lib/jekyll-emd-generator/version.rb

Constant Summary collapse

VERSION =
"0.1.16"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acl(doc, site) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/jekyll-emd-generator.rb', line 76

def self.acl(doc,site)

  dir = File.dirname(doc.path)
  file = site.in_source_dir(dir,"acl.json")
  if File.exist?(file)
    #
    #Jekyll.logger.info "", file
    #
    doc.data['acl'] = SafeYAML.load_file(file)
  end
end

.elements(doc, site) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jekyll-emd-generator.rb', line 64

def self.elements(doc,site)

  dir = File.dirname(doc.path)
  file = site.in_source_dir(dir,"elements.json")
  if File.exist?(file)
    #
    #Jekyll.logger.info "", file
    #
    doc.data['elements'] = SafeYAML.load_file(file)
  end
end

.offer(doc, site) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jekyll-emd-generator.rb', line 24

def self.offer(doc,site)

  dir = File.dirname(doc.path)
  file = site.in_source_dir(dir,"offer.json")
  if File.exist?(file)

    doc.data['offer'] = SafeYAML.load_file(file)
    #
    #Jekyll.logger.info "", file
    #
    # jekyll-seo-plugin @title
    # Der Product.name wird zu @title falls nicht im 
    # Frontmatter überschrieben
    if doc.data['title'].nil?
      doc.data['title'] = doc.data['offer']['name']
    end
    # jekyll-seo-plugin @description
    # Product.description wird zu @description falls nicht
    # im Frontmatter überschrieben
    if doc.data['description'].nil?
      doc.data['description'] = doc.data['offer']['description']
    end
    # jekyll-seo-plugin @image
    # Product.image wird zu @image falls nicht im
    # Frontmatter überschrieben
    if doc.data['image'].nil?
      image = site.in_source_dir(dir,doc.data['offer']['image'])
      if File.exist?(image)
        dimensions = FastImage.size(image)
        doc.data['image'] = {}
        doc.data['image']['path'] = '/' + dir + '/' + doc.data['offer']['image']
        doc.data['image']['width'] = dimensions[0]
        doc.data['image']['height'] = dimensions[1]
      else
        Jekyll.logger.warn "Missing:", image
      end
    end
  end
end

Instance Method Details

#generate(site) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jekyll-emd-generator.rb', line 8

def generate(site)

  site.pages.each do |page|
    if File.fnmatch( "index.{html,md}", page.path, File::FNM_EXTGLOB )
      ["elements"].each do |method|
        Generator.method(method).call(page,site)
      end
    end
    if File.fnmatch( "**/index.{html,md}", page.path, File::FNM_EXTGLOB )
      ["acl", "offer", "elements"].each do |method|
        Generator.method(method).call(page,site)
      end
    end
  end
end