forked from git/git-scm.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_file.rb
79 lines (71 loc) · 2.21 KB
/
doc_file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
# t.string :name
# t.timestamps
class DocFile < ApplicationRecord
has_many :doc_versions, dependent: :delete_all
has_many :versions, through: :doc_versions
scope :with_includes, -> { includes(doc_versions: %i[doc version]) }
@@true_lang = {
"de" => "Deutsch",
"en" => "English",
"es" => "Español",
"es_MX" => "Español (Mexico)",
"fr" => "Français",
"hu" => "magyar",
"id" => "Bahasa Indonesia",
"is" => "Íslenska",
"it" => "Italiano",
"ja" => "日本語",
"mr" => "मराठी",
"nb_NO" => "Norsk bokmål",
"nl" => "Nederlands",
"pl" => "Polski",
"pt_BR" => "Português (Brasil)",
"pt_PT" => "Português (Portugal)",
"ro" => "Română",
"ru" => "Русский",
"tr" => "Türkçe",
"uk" => "українська мова",
"zh_HANS-CN" => "简体中文",
"zh_HANT" => "繁體中文"
}
def true_lang
@@true_lang
end
def languages
doc_versions.select(:language).distinct.collect do |v|
[v[:language], @@true_lang[v[:language]] || v[:language]]
end
end
def version_changes(limit_size = 100)
unchanged_versions = []
changes = []
doc_versions = self.doc_versions.includes(:version).version_changes.limit(limit_size).to_a
doc_versions.each_with_index do |doc_version, i|
previous_doc_version = doc_versions[i + 1]
next unless previous_doc_version
sha2 = doc_version.doc.blob_sha
sha1 = previous_doc_version.doc.blob_sha
if sha1 == sha2
unchanged_versions << doc_version.name
else
if !unchanged_versions.empty?
if unchanged_versions.size == 1
changes << { name: "#{unchanged_versions.first} no changes", changed: false }
else
changes << { name: "#{unchanged_versions.last} → #{unchanged_versions.first} no changes",
changed: false }
end
unchanged_versions = []
end
changes << { name: doc_version.name, time: doc_version.committed, diff: previous_doc_version.diff(doc_version),
changed: true }
end
end
changes
end
# TODO: parse file for description
def description
""
end
end