reapack-index 1.0beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ class ReaPack::Index
2
+ class NamedNode
3
+ NAME_ATTR = 'name'.freeze
4
+
5
+ def self.tag;
6
+ raise "@tag is unset" unless @tag
7
+ @tag
8
+ end
9
+
10
+ def self.find_in(parent, name)
11
+ node = parent.element_children.find {|node|
12
+ node.name == tag && node[NAME_ATTR] == name
13
+ }
14
+
15
+ self.new node if node
16
+ end
17
+
18
+ def self.find_all(parent)
19
+ parent.element_children
20
+ .select {|node| node.name == tag }
21
+ .map {|node| self.new node }
22
+ end
23
+
24
+ def self.get(name, parent, create)
25
+ return unless parent
26
+
27
+ node = self.find_in parent, name
28
+
29
+ if create
30
+ node ||= self.new name, parent
31
+ end
32
+
33
+ node
34
+ end
35
+
36
+ def initialize(node, parent = nil)
37
+ return @node = node if parent.nil?
38
+
39
+ @is_new = true
40
+ @dirty = true
41
+
42
+ @node = Nokogiri::XML::Node.new self.class.tag, parent.document
43
+ @node[NAME_ATTR] = node
44
+ @node.parent = parent
45
+ end
46
+
47
+ attr_reader :node
48
+
49
+ def is_new?; !!@is_new; end
50
+ def modified?; !!@dirty; end
51
+
52
+ def name
53
+ @node[NAME_ATTR]
54
+ end
55
+
56
+ def empty?
57
+ @node.element_children.empty?
58
+ end
59
+
60
+ def remove
61
+ @node.remove
62
+ end
63
+
64
+ def children(tag)
65
+ @node.element_children.select {|node| node.name == tag }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ class ReaPack::Index
2
+ class Category < NamedNode
3
+ @tag = 'category'.freeze
4
+ end
5
+
6
+ class Package < NamedNode
7
+ @tag = 'reapack'.freeze
8
+
9
+ TYPE = 'type'.freeze
10
+
11
+ def initialize(node, parent = nil)
12
+ super
13
+
14
+ @versions = {}
15
+
16
+ read_versions
17
+ end
18
+
19
+ def modified?
20
+ super || @versions.values.any? {|ver| ver.modified? }
21
+ end
22
+
23
+ def type
24
+ @node[TYPE].to_s
25
+ end
26
+
27
+ def type=(new_type)
28
+ new_type ||= String.new
29
+
30
+ return if type == new_type
31
+
32
+ @node[TYPE] = new_type
33
+ @dirty = true
34
+ end
35
+
36
+ def has_version?(name)
37
+ @versions.has_key? name
38
+ end
39
+
40
+ def versions
41
+ @versions.values
42
+ end
43
+
44
+ def version(name)
45
+ if has_version? name
46
+ ver = @versions[name]
47
+ else
48
+ ver = @versions[name] = Version.new name, @node
49
+ end
50
+
51
+ if block_given?
52
+ yield ver
53
+ else
54
+ ver
55
+ end
56
+ end
57
+
58
+ private
59
+ def read_versions
60
+ Version.find_all(@node).each {|ver|
61
+ @versions[ver.name] = ver
62
+ }
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,35 @@
1
+ class WordpressChangelog < MetaHeader::Parser
2
+ CHANGELOG = /
3
+ Changelog\s*:\n
4
+ (.+?)\n\s*
5
+ ((?:--)?\]\]|\*\/)
6
+ /xm.freeze
7
+
8
+ VERSION = /\A[\s\*]+v([\d\.]+)(?:\s+(.+))?\Z/.freeze
9
+
10
+ def parse(input)
11
+ input.encode! Encoding::UTF_8, invalid: :replace
12
+
13
+ ver, changes = header[:version], header[:changelog]
14
+ return if ver.nil? || changes || CHANGELOG.match(input).nil?
15
+
16
+ $1.lines {|line| read line.lstrip }
17
+ end
18
+
19
+ def read(line)
20
+ if line =~ VERSION
21
+ @current = $1 == header[:version]
22
+ line = $2.to_s
23
+ end
24
+
25
+ return unless @current
26
+
27
+ if header[:changelog]
28
+ header[:changelog] += "\n"
29
+ else
30
+ header[:changelog] = String.new
31
+ end
32
+
33
+ header[:changelog] += line.chomp
34
+ end
35
+ end
@@ -0,0 +1,178 @@
1
+ class ReaPack::Index
2
+ class Version < NamedNode
3
+ @tag = 'version'.freeze
4
+
5
+ AUTHOR = 'author'.freeze
6
+ TIME = 'time'.freeze
7
+
8
+ def initialize(node, parent = nil)
9
+ super
10
+
11
+ @changelog = Changelog.new @node
12
+ end
13
+
14
+ def modified?
15
+ super || @changelog.modified?
16
+ end
17
+
18
+ def changelog=(new_text)
19
+ @changelog.text = new_text
20
+ end
21
+
22
+ def author
23
+ @node[AUTHOR].to_s
24
+ end
25
+
26
+ def author=(new_author)
27
+ new_author ||= String.new
28
+
29
+ return if author == new_author
30
+
31
+ if new_author.empty?
32
+ @node.remove_attribute AUTHOR
33
+ else
34
+ @node[AUTHOR] = new_author
35
+ end
36
+
37
+ @dirty = true
38
+ end
39
+
40
+ def time
41
+ Time.parse @node[TIME] if @node.has_attribute? TIME
42
+ end
43
+
44
+ def time=(new_time)
45
+ return if new_time == time
46
+
47
+ if new_time.nil?
48
+ @node.remove_attribute TIME
49
+ else
50
+ @node[TIME] = new_time.utc.iso8601
51
+ end
52
+
53
+ @dirty = true
54
+ end
55
+
56
+ def replace_sources
57
+ was_dirty = @dirty
58
+
59
+ old_sources = hash_sources children(Source::TAG)
60
+ .each {|node| node.remove }
61
+
62
+ yield
63
+
64
+ new_sources = hash_sources children(Source::TAG)
65
+ @dirty = was_dirty || old_sources != new_sources
66
+
67
+ if new_sources.empty?
68
+ raise Error, 'no sources found. @provides tag missing?'
69
+ end
70
+ end
71
+
72
+ def add_source(src, file = nil, url = nil)
73
+ src = Source.new src, file, url unless src.is_a? Source
74
+ src.make_node @node
75
+
76
+ @dirty = true
77
+ end
78
+
79
+ private
80
+ def hash_sources(nodes)
81
+ nodes.map {|src|
82
+ [src[Source::PLATFORM], src[Source::FILE], src.content]
83
+ }
84
+ end
85
+ end
86
+
87
+ class Source
88
+ TAG = 'source'.freeze
89
+ PLATFORM = 'platform'.freeze
90
+ FILE = 'file'.freeze
91
+
92
+ PLATFORMS = [
93
+ :all,
94
+ :windows, :win32, :win64,
95
+ :darwin, :darwin32, :darwin64,
96
+ ].freeze
97
+
98
+ def self.validate_platform(platform)
99
+ return unless platform # nil platform will be replaced by the default
100
+
101
+ unless PLATFORMS.include? platform.to_sym
102
+ raise Error, 'invalid platform %s' % platform
103
+ end
104
+ end
105
+
106
+ def initialize(platform = nil, file = nil, url = nil)
107
+ self.platform = platform
108
+ self.file = file
109
+ self.url = url
110
+ end
111
+
112
+ def platform=(new_platform)
113
+ new_platform = :all if new_platform.nil?
114
+
115
+ self.class.validate_platform new_platform
116
+
117
+ @platform = new_platform
118
+ end
119
+
120
+ attr_reader :platform
121
+ attr_accessor :file, :url
122
+
123
+ def make_node(parent)
124
+ @node = Nokogiri::XML::Node.new TAG, parent.document
125
+ @node.parent = parent
126
+ @node[PLATFORM] = @platform
127
+ @node[FILE] = @file if @file
128
+ @node.content = URI.escape @url
129
+ end
130
+ end
131
+
132
+ class Changelog
133
+ TAG = 'changelog'.freeze
134
+
135
+ def initialize(parent)
136
+ @parent = parent
137
+
138
+ @node = parent.element_children.find {|node| node.name == TAG }
139
+
140
+ if @node
141
+ cdata = @node.children.first
142
+ @text = cdata.content
143
+ else
144
+ @text = String.new
145
+ end
146
+ end
147
+
148
+ def modified?
149
+ !!@dirty
150
+ end
151
+
152
+ attr_reader :text
153
+
154
+ def text=(new_text)
155
+ new_text ||= String.new
156
+
157
+ if text == new_text
158
+ return
159
+ else
160
+ @dirty = true
161
+ end
162
+
163
+ return @node.remove if new_text.empty?
164
+
165
+ if @node
166
+ @node.children.each {|n| n.remove }
167
+ else
168
+ @node = Nokogiri::XML::Node.new TAG, @parent.document
169
+ @node.parent = @parent
170
+ end
171
+
172
+ cdata = Nokogiri::XML::CDATA.new @node.document, new_text
173
+ cdata.parent = @node
174
+
175
+ @text = new_text
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path '../lib', __FILE__
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
4
+
5
+ require 'reapack/index/gem_version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "reapack-index"
9
+ spec.version = ReaPack::Index::VERSION
10
+ spec.authors = ["cfillion"]
11
+ spec.email = ["reapack-index@cfillion.tk"]
12
+ spec.summary = %q{Package indexer for ReaPack-based repositories}
13
+ spec.homepage = "https://github.com/cfillion/reapack-indexer"
14
+ spec.license = "LGPL-3.0+"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'coveralls', '~> 0.8'
23
+ spec.add_development_dependency 'git', '~> 1.2'
24
+ spec.add_development_dependency 'minitest', '~> 5.8'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'simplecov', '~> 0.11'
27
+
28
+ spec.add_runtime_dependency 'colorize', '~> 0.7'
29
+ spec.add_runtime_dependency 'metaheader', '~> 1.0'
30
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
31
+ spec.add_runtime_dependency 'pandoc-ruby', '~> 1.0'
32
+ spec.add_runtime_dependency 'rugged', '~> 0.24.0b12'
33
+ end
@@ -0,0 +1 @@
1
+ *.exe
@@ -0,0 +1,148 @@
1
+ !include MUI2.nsh
2
+ !include Sections.nsh
3
+
4
+ !define VERSION "1.0beta2"
5
+ !define NAME "ReaPack Index ${VERSION}"
6
+ !define LONG_VERSION "0.1.0.0"
7
+
8
+ !define RUBY_VERSION "2.2.4"
9
+ !define RUBYINSTALLER_FILE "rubyinstaller-${RUBY_VERSION}.exe"
10
+ !define RUBYINSTALLER_URL \
11
+ "http://dl.bintray.com/oneclick/rubyinstaller/${RUBYINSTALLER_FILE}"
12
+
13
+ !define PANDOC_FILE "pandoc-1.16.0.2-windows.msi"
14
+ !define PANDOC_URL \
15
+ "https://github.com/jgm/pandoc/releases/download/1.16.0.2/${PANDOC_FILE}"
16
+
17
+ !define RUGGED_FILE "rugged-0.24.0b12-x86-mingw32.gem"
18
+ !define RUGGED_URL \
19
+ "https://github.com/cfillion/reapack-index/releases/download/v${VERSION}/${RUGGED_FILE}"
20
+
21
+ Name "${NAME}"
22
+ OutFile "reapack-index-${VERSION}.exe"
23
+ ShowInstDetails show
24
+ XPStyle on
25
+ RequestExecutionLevel user
26
+ SpaceTexts none
27
+
28
+ VIProductVersion "${LONG_VERSION}"
29
+ VIAddVersionKey "ProductName" "${NAME}"
30
+ VIAddVersionKey "ProductVersion" "${LONG_VERSION}"
31
+ VIAddVersionKey "FileDescription" "${NAME} Setup"
32
+ VIAddVersionKey "FileVersion" "${LONG_VERSION}"
33
+ VIAddVersionKey "LegalCopyright" "Copyright (C) 2015-2016 Christian Fillion"
34
+
35
+ !define ABORT_MSG "Installation aborted."
36
+
37
+ !insertmacro MUI_PAGE_WELCOME
38
+ !insertmacro MUI_PAGE_COMPONENTS
39
+ !insertmacro MUI_PAGE_INSTFILES
40
+ !insertmacro MUI_PAGE_FINISH
41
+
42
+ !insertmacro MUI_LANGUAGE "English"
43
+
44
+ !macro DOWNLOAD url file
45
+ NSISdl::download /TIMEOUT=30000 "${url}" "${file}"
46
+ Pop $R0
47
+ StrCmp $R0 "success" +4
48
+ DetailPrint "Error while downloading ${url}:"
49
+ DetailPrint " $R0"
50
+ Abort "${ABORT_MSG}"
51
+ !macroend
52
+
53
+ !macro EXEC_GUI cmd basename
54
+ ExecWait '${cmd}' $0
55
+ StrCmp $0 "0" +3
56
+ DetailPrint "${basename} failed with exit code $0"
57
+ Abort "${ABORT_MSG}"
58
+ !macroend
59
+
60
+ !macro EXEC_CLI cmd basename
61
+ DetailPrint 'Execute: ${basename}'
62
+ nsExec::ExecToStack '${cmd}'
63
+ Pop $0
64
+ StrCmp $0 "0" +5
65
+ Pop $1
66
+ DetailPrint $1
67
+ DetailPrint "`${basename}` failed with exit code $0"
68
+ Abort "${ABORT_MSG}"
69
+ !macroend
70
+
71
+ Section /o "Ruby for Windows" InstallRuby
72
+ InitPluginsDir
73
+ StrCpy $0 "$PLUGINSDIR\${RUBYINSTALLER_FILE}"
74
+ !insertmacro DOWNLOAD "${RUBYINSTALLER_URL}" $0
75
+
76
+ DetailPrint "Installing Ruby ${RUBY_VERSION}..."
77
+ !insertmacro EXEC_GUI '"$0" /VERYSILENT /TASKS=MODPATH' ${RUBYINSTALLER_FILE}
78
+
79
+ ; reload the path to use the one freshly set by the ruby installer
80
+ ReadRegStr $R0 HKCU "Environment" "Path"
81
+ System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("Path", R0).r2'
82
+ SectionEnd
83
+
84
+ Section /o "Rugged (libgit2)" InstallRugged
85
+ InitPluginsDir
86
+ StrCpy $0 "$PLUGINSDIR\${RUGGED_FILE}"
87
+ !insertmacro DOWNLOAD "${RUGGED_URL}" $0
88
+
89
+ DetailPrint "Installing rugged/libgit2 with pre-built C extensions..."
90
+ !insertmacro EXEC_CLI '"cmd" /C gem install $0' "gem install ${RUGGED_FILE}"
91
+ SectionEnd
92
+
93
+ Section /o "Pandoc" InstallPandoc
94
+ InitPluginsDir
95
+ StrCpy $0 "$PLUGINSDIR\${PANDOC_FILE}"
96
+ !insertmacro DOWNLOAD "${PANDOC_URL}" $0
97
+
98
+ DetailPrint "Installing Pandoc..."
99
+ !insertmacro EXEC_GUI '"msiexec" /i $0 /passive' ${PANDOC_FILE}
100
+ SectionEnd
101
+
102
+ Section "ReaPack-Index" InstallMain
103
+ SectionIn RO
104
+
105
+ DetailPrint "Installing reapack-index... (this can take a while)"
106
+
107
+ !insertmacro EXEC_CLI \
108
+ '"cmd" /C gem install reapack-index --version=${VERSION}' \
109
+ "gem install reapack-index"
110
+ SectionEnd
111
+
112
+ Function .onInit
113
+ nsExec::ExecToStack '"ruby" -e "require \"rugged\"'
114
+ Pop $0
115
+
116
+ StrCmp $0 "error" 0 +5 ; failed to launch ruby
117
+ SectionGetFlags ${InstallRuby} $1
118
+ IntOp $1 $1 | ${SF_SELECTED}
119
+ SectionSetFlags ${InstallRuby} $1
120
+ Goto +2 ; also install rugged
121
+
122
+ StrCmp $0 "1" 0 +4 ; rugged is not installed
123
+ SectionGetFlags ${InstallRugged} $1
124
+ IntOp $1 $1 | ${SF_SELECTED}
125
+ SectionSetFlags ${InstallRugged} $1
126
+
127
+ nsExec::ExecToStack '"pandoc" --version'
128
+ Pop $0
129
+
130
+ StrCmp $0 "error" 0 +4 ; failed to launch pandoc
131
+ SectionGetFlags ${InstallPandoc} $1
132
+ IntOp $1 $1 | ${SF_SELECTED}
133
+ SectionSetFlags ${InstallPandoc} $1
134
+ FunctionEnd
135
+
136
+ !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
137
+ !insertmacro MUI_DESCRIPTION_TEXT ${InstallRuby} \
138
+ "Download and install Ruby v${RUBY_VERSION} for Windows on your computer."
139
+
140
+ !insertmacro MUI_DESCRIPTION_TEXT ${InstallRugged} \
141
+ "Install a pre-built version of rugged, a Ruby bindings to the libgit2 C library."
142
+
143
+ !insertmacro MUI_DESCRIPTION_TEXT ${InstallPandoc} \
144
+ "Install Pandoc to enable automatic conversion from various document formats into RTF."
145
+
146
+ !insertmacro MUI_DESCRIPTION_TEXT ${InstallMain} \
147
+ "Install ReaPack's Package Indexer v${VERSION} on your computer."
148
+ !insertmacro MUI_FUNCTION_DESCRIPTION_END