Class: Jekyll::VersionedFiles::FileDocuments

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/versioned_files/filedocuments.rb

Constant Summary collapse

DIFF_HEADER_REGEXP =
%r!diff.+?@@.+?@@\n+?(?<=.)?!m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileDocuments

Initialize FileDocuments.

Returns nothing.



12
13
14
15
16
# File 'lib/jekyll/versioned_files/filedocuments.rb', line 12

def initialize
  @diffoptions = VersionedFiles.format_options['diff_ignore']
  @fname_paths = VersionedFiles.files
  @style       = Styler.new
end

Instance Attribute Details

#diffoptionsObject (readonly)

Returns the value of attribute diffoptions.



4
5
6
# File 'lib/jekyll/versioned_files/filedocuments.rb', line 4

def diffoptions
  @diffoptions
end

#fname_pathsObject (readonly)

Returns the value of attribute fname_paths.



4
5
6
# File 'lib/jekyll/versioned_files/filedocuments.rb', line 4

def fname_paths
  @fname_paths
end

#line_countObject

Returns the value of attribute line_count.



5
6
7
# File 'lib/jekyll/versioned_files/filedocuments.rb', line 5

def line_count
  @line_count
end

Instance Method Details

#createObject

Creates the collection of versioned files in site.source directory

Returns nothing



21
22
23
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
# File 'lib/jekyll/versioned_files/filedocuments.rb', line 21

def create
  revisions do |orig_file, sha_list|
    sha_list.each_with_index do |sha, i|
      ver = (i + 1).to_s
      # Git revisioned file
      composeversions(orig_file, sha, ver) do |content, data, file_path|
        # dont re-write files
        if File.exist?(file_path)
          linecount(file_path)
          next
        end

        version_content = FrontMatter.new(data)
        version_content.content = content 
        write(file_path, version_content.update)
        linecount(file_path)
      end
    end

    sha_list.map!.with_index { |sha, i| [] << sha << (i + 1) }
    # Git Diff combination files
    composediffs(orig_file, line_count, sha_list.combination(2)) do |content, data, file_path|
      content.sub!(DIFF_HEADER_REGEXP, '')
      if change?(content)
        VersionedFiles.frontmatter["no_change"] = false
        styled_content = @style.style(content)
        data.merge!(@style.stats.final)
      else
        VersionedFiles.frontmatter["no_change"] = "no_change"
        data["no_change"] = true
      end

      fm = FrontMatter.new(data).create
      diff_file = fm << styled_content
      write(file_path, diff_file)
    end
  end
end