site/_plugins/data_page_generator.rb
def generate(site)
      # page_gen_dirs determines whether we want to generate index pages
      # (name/index.html) or standard files (name.html). This information
      # is passed to the DataPage constructor, which sets the @dir variable
      # as required by this directive
      index_files = site.config['page_gen-dirs'] == true

      # data contains the specification of the data for which we want to generate
      # the pages (look at the README file for its specification)
      data = site.config['page_gen']
      if data
        data.each do |data_spec|
          index_files_for_this_data = data_spec['index_files'] != nil ? data_spec['index_files'] : index_files
          template = data_spec['template'] || data_spec['data']
          name = data_spec['name']
          dir = data_spec['dir'] || data_spec['data']
          extension = data_spec['extension'] || "html"

          if site.layouts.key? template
            # records is the list of records defined in _data.yml
            # for which we want to generate different pages
            records = nil
            data_spec['data'].split('.').each do |level|
              if records.nil?
                records = site.data[level]
              else
                records = records[level]
              end
            end

            # apply filtering conditions:
            # - filter requires the name of a boolean field
            # - filter_condition evals a ruby expression
            records = records.select { |r| r[data_spec['filter']] } if data_spec['filter']
            records = records.select { |record| eval(data_spec['filter_condition']) } if data_spec['filter_condition']

            records.each do |record|
              site.pages << DataPage.new(site, site.source, index_files_for_this_data, dir, record, name, template, extension)
            end
          else
            puts "error (datapage_gen). could not find template #{template}" if not site.layouts.key? template
          end
        end
      end
    end
# generate loops over _config.yml/page_gen invoking the DataPage
# constructor for each record for which we want to generate a page
generate loops over _config.yml/page_gen invoking the DataPage
constructor for each record for which we want to generate a page
generate loops over _config . yml / page_gen invoking the DataPage constructor for each record for which we want to generate a page
def generate(site)
      index_files = site.config['page_gen-dirs'] == true
      data = site.config['page_gen']
      if data
        data.each do |data_spec|
          index_files_for_this_data = data_spec['index_files'] != nil ? data_spec['index_files'] : index_files
          template = data_spec['template'] || data_spec['data']
          name = data_spec['name']
          dir = data_spec['dir'] || data_spec['data']
          extension = data_spec['extension'] || "html"
          if site.layouts.key? template
            records = nil
            data_spec['data'].split('.').each do |level|
              if records.nil?
                records = site.data[level]
              else
                records = records[level]
              end
            end
            records = records.select { |r| r[data_spec['filter']] } if data_spec['filter']
            records = records.select { |record| eval(data_spec['filter_condition']) } if data_spec['filter_condition']
            records.each do |record|
              site.pages << DataPage.new(site, site.source, index_files_for_this_data, dir, record, name, template, extension)
            end
          else
            puts "error (datapage_gen). could not find template #{template}" if not site.layouts.key? template
          end
        end
      end
    end
def generate ( site ) index_files = site . config [ 'page_gen-dirs' ] == true data = site . config [ 'page_gen' ] if data data . each do | data_spec | index_files_for_this_data = data_spec [ 'index_files' ] != nil ? data_spec [ 'index_files' ] : index_files template = data_spec [ 'template' ] || data_spec [ 'data' ] name = data_spec [ 'name' ] dir = data_spec [ 'dir' ] || data_spec [ 'data' ] extension = data_spec [ 'extension' ] || "html" if site . layouts . key? template records = nil data_spec [ 'data' ] . split ( '.' ) . each do | level | if records . nil? records = site . data [ level ] else records = records [ level ] end end records = records . select { | r | r [ data_spec [ 'filter' ] ] } if data_spec [ 'filter' ] records = records . select { | record | eval ( data_spec [ 'filter_condition' ] ) } if data_spec [ 'filter_condition' ] records . each do | record | site . pages << DataPage . new ( site , site . source , index_files_for_this_data , dir , record , name , template , extension ) end else puts "error (datapage_gen). could not find template #{template}" if not site . layouts . key? template end end end end
generate loops over _config.yml/page_gen invoking the DataPage
constructor for each record for which we want to generate a page
generate loops over _config . yml / page_gen invoking the DataPage constructor for each record for which we want to generate a page
# page_gen_dirs determines whether we want to generate index pages # (name/index.html) or standard files (name.html). This information # is passed to the DataPage constructor, which sets the @dir variable # as required by this directive # data contains the specification of the data for which we want to generate # the pages (look at the README file for its specification) # records is the list of records defined in _data.yml # for which we want to generate different pages # apply filtering conditions: # - filter requires the name of a boolean field # - filter_condition evals a ruby expression
site