docbook_files 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/About.org +77 -0
  2. data/Gemfile +7 -1
  3. data/Gemfile.lock +27 -0
  4. data/Guardfile +6 -0
  5. data/History.txt +7 -0
  6. data/README.md +7 -7
  7. data/Rakefile +6 -4
  8. data/bin/docbook_files +6 -88
  9. data/lib/docbook_files/app.rb +212 -0
  10. data/lib/docbook_files/docbook.rb +2 -1
  11. data/lib/docbook_files/file_data.rb +19 -25
  12. data/spec/docbook_files/app_spec.rb +51 -0
  13. data/spec/docbook_files/docbook_spec.rb +72 -0
  14. data/spec/docbook_files/file_data_spec.rb +78 -0
  15. data/{.DS_Store → spec/fixtures/.DS_Store} +0 -0
  16. data/{test → spec}/fixtures/book-nonexisting.xml +0 -0
  17. data/{test → spec}/fixtures/bookxi.xml +0 -0
  18. data/{test → spec}/fixtures/c4/chapter4xi.xml +0 -0
  19. data/{test → spec}/fixtures/chapter2xi.xml +0 -0
  20. data/{test → spec}/fixtures/chapter3xi.xml +0 -0
  21. data/{test → spec}/fixtures/no-ns.xml +0 -0
  22. data/{test → spec}/fixtures/no-xml.xml +0 -0
  23. data/{test → spec/fixtures/refs}/.DS_Store +0 -0
  24. data/{test → spec}/fixtures/refs/book-simple-err.xml +0 -0
  25. data/{test → spec}/fixtures/refs/book-simple.xml +0 -0
  26. data/{test → spec}/fixtures/refs/bookxi.xml +0 -0
  27. data/{test → spec}/fixtures/refs/c4/chapter4xi.xml +0 -0
  28. data/{test → spec}/fixtures/refs/chapter2xi.xml +3 -0
  29. data/{test → spec}/fixtures/refs/chapter3xi.xml +0 -0
  30. data/{test → spec}/fixtures/refs/img/orange.jpeg +0 -0
  31. data/{test → spec}/fixtures/refs/img/orange.png +0 -0
  32. data/spec/fixtures/refs/img/ship.svg +3 -0
  33. data/{test → spec}/fixtures/refs/section1xi.xml +0 -0
  34. data/{test → spec}/fixtures/section1xi.xml +0 -0
  35. data/spec/spec_helper.rb +2 -1
  36. data/version.txt +1 -1
  37. metadata +38 -38
  38. data/.gitignore +0 -7
  39. data/test/docbook_files/test_docbook.rb +0 -76
  40. data/test/docbook_files/test_file_data.rb +0 -83
  41. data/test/test_docbook_files.rb +0 -6
data/About.org ADDED
@@ -0,0 +1,77 @@
1
+ #+title: Notizen
2
+ #+description: Notizen und Aufgaben für docbook_files
3
+
4
+ * Eigenschaften
5
+
6
+ ** Grafische Ausgabe der Dateistruktur
7
+
8
+ *** Graphviz?
9
+ Für Ruby gibt es das viele Module, siehe zum Beispiel graph.
10
+
11
+ graph version 2.3.0 has been released!
12
+
13
+ * <https://github.com/seattlerb/graph>
14
+
15
+ Graph is a type of hash that outputs in graphviz's dot format. It
16
+ comes with a command-line interface that is easily pluggable.
17
+
18
+ It ships with plugins to graph dependencies and status of installed
19
+ rubygems, rake tasks, homebrew ports, mac ports, and freebsd ports,
20
+ coloring leaf nodes blue, outdated nodes red, and outdated leaf nodes
21
+ purple (red+blue).
22
+
23
+
24
+ ** Detailausgabe gegenüber Hierarchie
25
+
26
+ Die Hierarchie ist die Hauptausgabe. Allerdings kann man sich über
27
+ '--details' auch die Detailangaben zu allen beteiligten Dateien
28
+ ausgeben lassen. Hier werden alle Angaben ausgegeben, die oben
29
+ optional sind.
30
+
31
+ Besonders wichtig ist die Zusammenfassung, also Dateien, die an
32
+ mehreren Stellen eingebunden werden, also mehrere Eltern haben!
33
+
34
+ Die Detailausgabe führt dann über zum Releasedokument.
35
+
36
+ ** Releasedokument
37
+
38
+ Die Ausgabe kann in einer Datei gespeichert werden, die dann als
39
+ Manifest für ein Archiv dienen kann. Anhand des Dokuments kann man
40
+ schauen, ob die vorliegenden Dateien dem gespeicherten Stand
41
+ entsprechen.
42
+
43
+ ** Ausgabeformate
44
+ *** Graphviz & HTML
45
+ *** TODO YAML, JSON
46
+ *** DocBook
47
+ *** RDF?
48
+
49
+ ** Zusammenhang mit SCM
50
+
51
+ Wie bei Bones?
52
+
53
+ ** DONE Änderung Anzeige
54
+ *** Hierarchie
55
+
56
+ Nur der Hierarchiebaum, aber mit längeren Namen. Das heißt, die
57
+ Dateien werden mit Pfad angezeigt, mit relativem zum Masterdokument.
58
+
59
+ Falls zu lang am Anfang kürzen mit Ellipse.
60
+
61
+ URIs oder nicht relative Dateien werden mit dem Anfang angezeigt,
62
+ ggf. in der Mitte gekürzt.
63
+
64
+ *** Zusammenfassung
65
+
66
+ * X Dateien
67
+ * Y inkludierte DocBooks
68
+ * Z referenzierte
69
+
70
+ YAML/JSON übernehmen und seinen eigenen machen.
71
+ *** Details
72
+
73
+ Die restlichen Angaben werden in die optionalen Details
74
+ verschoben. Die Optionen sind dann nicht mehr notwendig.
75
+
76
+ Wenn jemand den Bericht nicht mag, kann er gern die Daten über
77
+
data/Gemfile CHANGED
@@ -5,5 +5,11 @@ gem "term-ansicolor"
5
5
  gem "wand"
6
6
 
7
7
  group :development do
8
- gem "bones"
8
+ gem "bones"
9
+ gem 'turn'
10
+ gem 'rspec'
11
+ gem 'guard'
12
+ gem 'rb-fsevent'
13
+ gem 'growl_notify'
14
+ gem 'guard-rspec'
9
15
  end
data/Gemfile.lock CHANGED
@@ -1,17 +1,38 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ ansi (1.3.0)
4
5
  bones (3.7.1)
5
6
  little-plugger (>= 1.1.2)
6
7
  loquacious (>= 1.8.1)
7
8
  rake (>= 0.8.7)
9
+ diff-lcs (1.1.3)
10
+ growl_notify (0.0.3)
11
+ rb-appscript
12
+ guard (0.8.4)
13
+ thor (~> 0.14.6)
14
+ guard-rspec (0.5.0)
15
+ guard (>= 0.8.4)
8
16
  libxml-ruby (2.2.2)
9
17
  little-plugger (1.1.2)
10
18
  loquacious (1.9.0)
11
19
  mime-types (1.16)
12
20
  rake (0.9.2)
21
+ rb-appscript (0.6.1)
22
+ rb-fsevent (0.4.3.1)
23
+ rspec (2.6.0)
24
+ rspec-core (~> 2.6.0)
25
+ rspec-expectations (~> 2.6.0)
26
+ rspec-mocks (~> 2.6.0)
27
+ rspec-core (2.6.4)
28
+ rspec-expectations (2.6.0)
29
+ diff-lcs (~> 1.1.2)
30
+ rspec-mocks (2.6.0)
13
31
  safe_shell (1.0.1)
14
32
  term-ansicolor (1.0.6)
33
+ thor (0.14.6)
34
+ turn (0.8.3)
35
+ ansi
15
36
  wand (0.4)
16
37
  mime-types
17
38
  safe_shell (~> 1.0.0)
@@ -21,6 +42,12 @@ PLATFORMS
21
42
 
22
43
  DEPENDENCIES
23
44
  bones
45
+ growl_notify
46
+ guard
47
+ guard-rspec
24
48
  libxml-ruby
49
+ rb-fsevent
50
+ rspec
25
51
  term-ansicolor
52
+ turn
26
53
  wand
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ # -*- encoding:utf-8; mode:ruby -*-
2
+ guard 'rspec', :version => 2, :cli => '--color --format nested' do
3
+ watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.3.0 / 2011-10-11
2
+
3
+ * Reorganized output
4
+ * Added --details option and output
5
+ * Reorganize library
6
+ * Move to RSpec for testing
7
+
1
8
  == 0.2.0 / 2011-10-10
2
9
 
3
10
  * Added search for referenced files (e.g. media files included via a 'fileref' attribute)
data/README.md CHANGED
@@ -8,21 +8,21 @@ Features
8
8
 
9
9
  * lists and checks included files (XInclude)
10
10
  * lists and checks referenced files (media files and others, specidifed by _fileref_)
11
+ * shows errors, e.g. not existing files
12
+ * provides a detail listing
11
13
 
12
14
  Synopsis
13
15
  --------
14
16
 
15
- docbook_files is a command line application, bin/docbook_files, which checks the files that are included or referenced in a DocBook 5 project. (Note: In version 0.1.0 we are only checking included files, but that will change.)
17
+ docbook_files is a command line application, bin/docbook_files, which checks the files that are included or referenced in a DocBook 5 project.
16
18
 
17
- docbook_files myproject.xml
19
+ docbook_files myproject.xml
18
20
 
19
- This will result in a indentet list of the file names, starting from file _myproject.xml_ and following every XInclude link or _fileref_ reference. _fileref_ attributes are used in _mediaobject_ tags to specify external image, video, and audio files. Files that could not be found are shown in red.
21
+ This will result in a overview listing of the file names, starting from file _myproject.xml_ and following every XInclude link or _fileref_ reference. _fileref_ attributes are used in _mediaobject_ tags to specify external image, video, and audio files. Files that could not be found are shown in red.
20
22
 
21
- Using options the output can be enhanced with more file information, use the classical _docbook_files --help_ to see all available options. They range from file size to MIME types and XML namespaces. Example:
23
+ docbook_files --details myproject.xml
22
24
 
23
- docbook_files --ts --namespace myproject.xml
24
-
25
- would result in a list with the added information of the last modified timestamp and the XML namespace of each XML file.
25
+ The --details option adds, well yes, details to the overview: Size, type information, timestamp and checksum.
26
26
 
27
27
  Requirements
28
28
  ------------
data/Rakefile CHANGED
@@ -1,12 +1,15 @@
1
- #-*- encoding: utf-8 ; mode:ruby -*-
1
+ #-*- mode:ruby -*-
2
2
  begin
3
3
  require 'bones'
4
4
  rescue LoadError
5
5
  abort '### Please install the "bones" gem ###'
6
6
  end
7
7
 
8
- task :default => 'test:run'
9
- task 'gem:release' => 'test:run'
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new
10
+
11
+ task :default => 'spec'
12
+ task 'gem:release' => 'spec'
10
13
 
11
14
  Bones {
12
15
  name 'docbook_files'
@@ -14,7 +17,6 @@ Bones {
14
17
  email 'dev@textmulch.de'
15
18
  url 'http://github.com/rvolz/docbook_files/'
16
19
  ignore_file '.gitignore'
17
- ignore_file 'About.org'
18
20
  depend_on 'libxml-ruby'
19
21
  depend_on 'term-ansicolor'
20
22
  depend_on 'wand'
data/bin/docbook_files CHANGED
@@ -4,95 +4,13 @@
4
4
  #
5
5
 
6
6
  require 'rubygems'
7
- #require "bundler/setup"
8
- require 'optparse'
9
- #require 'yaml'
10
- #require 'json'
11
- require 'term/ansicolor'
12
-
13
- class String
14
- include Term::ANSIColor
15
- end
16
-
17
-
18
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib docbook_files]))
19
-
20
- banner = <<EOB
21
- docbook_files, Version #{DocbookFiles::VERSION}
22
-
23
- Displays the include hierarchy of a DocBook 5 project.
24
- Use the options to see additional information about each file.
25
- Files that could not be found are shown in red.
26
-
27
- Usage: docbook_files [options] <DOCBOOK-FILE>
28
- EOB
29
-
30
- @output_format = :screen
31
-
32
- props = []
33
- opts = OptionParser.new
34
- ivs = DocbookFiles::FileData.init_vars
35
- ivs.each do |k,v|
36
- opts.on("--#{k.to_s}","#{v}") {|val| props << k}
37
- end
38
- opts.banner = banner
39
- rest = opts.parse(ARGV)
40
-
41
- # Print banner if called without arguments
42
- if rest.length < 1
43
- puts opts.to_s
44
- exit 1
45
- end
46
-
47
- unless File.exists?(rest[0])
48
- STDERR.puts "Error: File #{rest[0]} not found."
49
- exit 1
7
+ begin
8
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib docbook_files]))
9
+ rescue LoadError
10
+ require 'docbook_files'
50
11
  end
51
12
 
52
- # The main routine
53
- puts("docbook_status, Version #{DocbookFiles::VERSION}") if @output_format == :screen
54
- dbf = DocbookFiles::Docbook.new(rest[0])
55
- table = dbf.list_as_table([:name,:exists]+props)
56
- puts
57
- puts 'File Hierarchy'
58
- puts '-'*80
59
-
60
- output_string = "%s %s" + props.map{|p| " %s"}.join
61
-
62
- def emptyval?(val)
63
- if val.nil?
64
- true
65
- else
66
- if (val.class == String)
67
- val.empty?
68
- else
69
- false
70
- end
71
- end
72
- end
13
+ DocbookFiles.run
73
14
 
74
- table.each_with_index do |t,index|
75
- vals = ['-'*t[:level]+'>',t[:name]] + props.map {|p|
76
- if (emptyval?(t[p]))
77
- '<>'
78
- else
79
- t[p]
80
- end
81
- }
82
- output = output_string % vals
83
- if (index == 0)
84
- output = "+" + output
85
- elsif (index == table.length-1)
86
- output = "+" + output
87
- else
88
- output = "|" + output
89
- end
90
- if t[:exists] == false
91
- puts output.red
92
- else
93
- puts output
94
- end
95
- end
15
+ #EOF
96
16
 
97
- puts
98
- exit 0
@@ -0,0 +1,212 @@
1
+ # -*-encoding:utf-8-*-
2
+
3
+ require 'optparse'
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'term/ansicolor'
7
+
8
+ class String
9
+ include Term::ANSIColor
10
+ end
11
+
12
+ module DocbookFiles
13
+
14
+ # Create a new instance of App, and run the +docbook_files+ application given
15
+ # the command line _args_.
16
+ #
17
+ def self.run( args = nil )
18
+ args ||= ARGV.dup.map! { |v| v.dup }
19
+ ::DocbookFiles::App.new.run args
20
+ end
21
+
22
+ class App
23
+ @@banner = <<EOB
24
+ docbook_files, Version #{DocbookFiles::VERSION}
25
+
26
+ Displays the include hierarchy of a DocBook 5 project.
27
+ Use the options to see additional information about each file.
28
+ Files that could not be found are shown in red.
29
+
30
+ Usage: docbook_files [options] <DOCBOOK-FILE>
31
+ EOB
32
+
33
+ def initialize(opts = {})
34
+ opts[:stdout] ||= $stdout
35
+ opts[:stderr] ||= $stderr
36
+ @opts = opts
37
+ @stdout = opts[:stdout]
38
+ @stderr = opts[:stderr]
39
+ @opts[:output_format] ||= :screen
40
+ @opts[:details] ||= false
41
+ @props = [:name, :full_name, :namespace, :docbook,
42
+ :version, :tag, :parent, :exists, :ts, :size, :checksum, :mime]
43
+ end
44
+
45
+ def run(args)
46
+ opts = OptionParser.new
47
+ opts.on('--details','List file details') {|val| @opts[:details] = true}
48
+ # opts.on('--outputformat=yaml|json',['json','yaml'],
49
+ # 'Return the result in YAML or JSON format instead of printing it') {|format|
50
+ # case
51
+ # when format == 'yaml'
52
+ # @opts[:output_format] = :yaml
53
+ # when format == 'json'
54
+ # @opts[:output_format] = :json
55
+ # else
56
+ # STDERR.puts "Unknown output format #{format}. Using screen output.".orange
57
+ # end
58
+ # }
59
+
60
+ opts.banner = @@banner
61
+ rest = opts.parse(args)
62
+
63
+ # Print banner if called without arguments
64
+ if rest.length < 1
65
+ @stdout.puts opts.to_s
66
+ exit 1
67
+ end
68
+
69
+ # The main routine
70
+ @stdout.puts("docbook_files, Version #{DocbookFiles::VERSION}") if @opts[:output_format] == :screen
71
+ unless File.exists?(rest[0])
72
+ @stderr.puts "Error: File #{rest[0]} not found.".red
73
+ exit 1
74
+ end
75
+
76
+ begin
77
+ dbf = DocbookFiles::Docbook.new(rest[0])
78
+ table = dbf.list_as_table(@props)
79
+ rescue => exc
80
+ @stderr.puts exc.inspect.red
81
+ end
82
+ output(table)
83
+ end
84
+
85
+ # Terminal output to @stdout
86
+ def output(table)
87
+ output_string = "%3d %-60s %4s %10s"
88
+ @stdout.puts
89
+ @stdout.puts 'File Hierarchy'.bold
90
+ @stdout.puts "%3s %-60s %4s %10s" % ['Lvl', 'File','Type','Size']
91
+ @stdout.puts '-'*80
92
+ sum_size = 0
93
+ sum_not_existing = 0
94
+ table.each do |t|
95
+ output = output_string % [t[:level],
96
+ format_name(t[:level],t[:full_name],table[0][:full_name]),
97
+ t[:type].to_s,
98
+ format_size(t[:size])]
99
+ sum_size += t[:size]
100
+ if t[:exists] == false
101
+ @stdout.puts output.red
102
+ sum_not_existing += 1
103
+ else
104
+ @stdout.puts output
105
+ end
106
+ end
107
+ @stdout.puts '-'*80
108
+ summary = "#{table.length} file(s) with approx. #{format_size(sum_size)}."
109
+ if sum_not_existing > 0
110
+ summary += " #{sum_not_existing} file(s) not found.".red
111
+ end
112
+ @stdout.puts summary
113
+ if @opts[:details]
114
+ @stdout.puts
115
+ @stdout.puts "Details".bold
116
+ table.each do |t|
117
+ fname = format_name(0,t[:full_name],table[0][:full_name])
118
+ @stdout.puts "File: %s" % [(t[:exists] ? fname : fname.red)]
119
+ if (t[:type] == FileData::TYPE_MAIN)
120
+ @stdout.puts "Main file"
121
+ elsif (t[:type] == FileData::TYPE_INCLUDE)
122
+ @stdout.puts "Included by: %s" % [t[:parent]]
123
+ else
124
+ @stdout.puts "Referenced by: %s" % [t[:parent]]
125
+ end
126
+ next unless t[:exists]
127
+ @stdout.puts "Size: %s (%d)" % [format_size(t[:size]),t[:size]]
128
+ if t[:docbook]
129
+ @stdout.puts "Type: DocBook, Version #{t[:version]}, Tag: #{t[:tag]}"
130
+ else
131
+ @stdout.puts "MIME: #{val_s(t[:mime])}"
132
+ end
133
+ @stdout.puts "Timestamp: %s" % [t[:ts]]
134
+ @stdout.puts "Checksum: %s" % [t[:checksum]]
135
+ @stdout.puts
136
+ end
137
+ end
138
+ end
139
+
140
+
141
+ # Format the filename to indicate the level in the hierarchy.
142
+ # Indentation = two spaces per level.
143
+ #
144
+ # If the file is located somewhere below the main file, only the
145
+ # relative part of the path is shown, else the full path.
146
+ # If the resulting string is too long for display it is shortened.
147
+ #
148
+ def format_name(level, full_name, main_name)
149
+ main_dir = File.dirname(main_name)
150
+ md = full_name.match("^#{main_dir}/")
151
+ if md.nil?
152
+ nname = full_name
153
+ else
154
+ nname = md.post_match
155
+ end
156
+ lnname = ' '*level+nname
157
+ if (lnname.length > 60)
158
+ lnname[0..3]+'...'+lnname[-54,lnname.length-1]
159
+ else
160
+ lnname
161
+ end
162
+ end
163
+
164
+ # :stopdoc:
165
+ KB = 1024
166
+ MB = 1048576
167
+ GB = 1073741824
168
+ TB = 1099511627776
169
+ PB = 1125899906842624
170
+ # :startdoc:
171
+
172
+ # Format a file size for human consumption.
173
+ # Sizes >= 1PB will return 'XXL'
174
+ def format_size(sz)
175
+ if (emptyval?(sz))
176
+ '-'
177
+ else
178
+ case
179
+ when sz < KB then "#{sz}B"
180
+ when sz >= KB && sz < MB then "#{sz/KB}KB"
181
+ when sz >= MB && sz < GB then "#{sz/MB}MB"
182
+ when sz >= GB && sz < TB then "#{sz/GB}GB"
183
+ when sz >= TB && sz < PB then "#{sz/TB}TB"
184
+ else
185
+ "XXL"
186
+ end
187
+ end
188
+ end
189
+
190
+ # Return a string for the value, '<>' if there is none.
191
+ def val_s(val)
192
+ if emptyval?(val)
193
+ '-'
194
+ else
195
+ val.to_s
196
+ end
197
+ end
198
+
199
+ # Check whether the value is nil or empty.
200
+ def emptyval?(val)
201
+ if val.nil?
202
+ true
203
+ else
204
+ if (val.class == String)
205
+ val.empty?
206
+ else
207
+ false
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
@@ -23,7 +23,7 @@ module DocbookFiles
23
23
 
24
24
  # Return the FileData tree representing the include
25
25
  # hierarchy.
26
- #
26
+ #
27
27
  def list
28
28
  @fd_tree ||= analyze_file(@main_name,File.dirname(@main_name))
29
29
  @fd_tree
@@ -128,5 +128,6 @@ private
128
128
  fl.includes = files.map {|f| analyze_file(f,parent_dir,fl)}
129
129
  fl
130
130
  end
131
+
131
132
  end
132
133
  end
@@ -7,13 +7,13 @@ module DocbookFiles
7
7
  # Data about a member file of a DocBook project
8
8
  class FileData
9
9
 
10
- # file name, full file path, existence flag, last modified timestamp, size in bytes
11
- # SHA1 checksum, MIME type, array of included FileDatas
12
- #attr_accessor :name, :full_name, :exists, :ts, :size, :checksum, :mime, :includes
13
-
14
- # XML namespace, Flag for DocBook NS, DocBook version, start tag
15
- #attr_accessor :namespace, :docbook, :version, :tag
16
-
10
+ # Type for the main/master file
11
+ TYPE_MAIN = :main
12
+ # Type for referenced files
13
+ TYPE_REFERENCE = :ref
14
+ # Type for included files
15
+ TYPE_INCLUDE = :inc
16
+
17
17
  attr_accessor :name, :exists, :includes, :refs
18
18
 
19
19
  def FileData.init_vars()
@@ -79,36 +79,30 @@ module DocbookFiles
79
79
  self.traverse([:name])
80
80
  end
81
81
 
82
- # Return a hash with the values for the passed symbols.
83
- # If the property list is empty all instance variables
84
- # are used, except the include.
82
+ # Return a hash with the values for the passed symbols.
83
+ # The type is added.
85
84
  #
86
85
  # Example: to_hash([:name, :mime]) would return
87
86
  # {:name => "name", :mime => "application/xml"}.
88
87
  #
89
- def to_hash(props=[])
90
- me_hash = {}
91
- if (props.empty?)
92
- ivs = self.instance_variables
93
- ivs.delete(:@includes)
94
- props = ivs.map {|iv| ivs = iv.to_s; ivs[1,ivs.length].to_sym}
95
- end
88
+ def to_hash(props,type)
89
+ me_hash = {:type => type}
96
90
  props.each {|p| me_hash[p] = self.send(p)}
97
91
  me_hash
98
92
  end
99
93
 
100
94
  # Return a tree-like array of maps with the
101
95
  # requested properties (symbols)
102
- def traverse(props=[])
103
- me = self.to_hash(props)
96
+ def traverse(props=[],type=TYPE_MAIN)
97
+ me = self.to_hash(props,type)
104
98
  me2 = [me]
105
99
  unless @refs.empty?()
106
- me2 += @refs.map {|r| r.to_hash(props)}
100
+ me2 += @refs.map {|r| r.to_hash(props,TYPE_REFERENCE)}
107
101
  end
108
102
  if @includes.empty?()
109
103
  me2
110
104
  else
111
- me2 + @includes.map {|i| i.traverse(props)}
105
+ me2 + @includes.map {|i| i.traverse(props,TYPE_INCLUDE)}
112
106
  end
113
107
  end
114
108
 
@@ -116,15 +110,15 @@ module DocbookFiles
116
110
  # requested properties (symbols). Each entry gets a level
117
111
  # indicator (:level) to show the tree-level.
118
112
  #
119
- def traverse_as_table(props=[],level=0)
120
- me = self.to_hash(props)
113
+ def traverse_as_table(props,level=0,type=TYPE_MAIN)
114
+ me = self.to_hash(props,type)
121
115
  me[:level] = level
122
116
  me2 = [me]
123
117
  unless @refs.empty?()
124
- me2 += @refs.map {|r| x = r.to_hash(props); x[:level] = level+1; x}
118
+ me2 += @refs.map {|r| x = r.to_hash(props,TYPE_REFERENCE); x[:level] = level+1; x}
125
119
  end
126
120
  unless @includes.empty?()
127
- me2 += @includes.map {|i| i.traverse_as_table(props,level+1)}
121
+ me2 += @includes.map {|i| i.traverse_as_table(props,level+1,TYPE_INCLUDE)}
128
122
  end
129
123
  me2.flatten
130
124
  end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require_relative '../spec_helper'
3
+
4
+ module DocbookFiles
5
+ describe App do
6
+
7
+ describe "displays file names" do
8
+ it "according to level" do
9
+ a = App.new
10
+ main_n = '/dir1/dir2/dir3/book.xml'
11
+ main_d = '/dir1/dir2/dir3/'
12
+ a.format_name(0,main_n,main_n).should == 'book.xml'
13
+ a.format_name(2,main_d+'chapter.xml',main_n).should == ' chapter.xml'
14
+ a.format_name(3,main_d+'dir4/chapter.xml',main_n).should == ' dir4/chapter.xml'
15
+ end
16
+
17
+ it "in full when not below main file" do
18
+ a = App.new
19
+ main_n = '/dir1/dir2/dir3/book.xml'
20
+ main_d = '/dir1/dir2/dir3/'
21
+ a.format_name(2,'/dir1/dir2/chapter4.xml',main_n).should == ' /dir1/dir2/chapter4.xml'
22
+ end
23
+
24
+ it "shortened when too long" do
25
+ a = App.new
26
+ main_d = '/dir1/dir2'*5
27
+ main_d2 = '/dir0/dir1/dir2'*5
28
+ main_n = main_d+'/book.xml'
29
+ a.format_name(2,main_d+'/chapter.xml',main_n).should == ' chapter.xml'
30
+ expected = " ...r0/dir1/dir2/dir0/dir1/dir2/dir0/dir1/dir2/chapter.xml"
31
+ a.format_name(2,main_d2+'/chapter.xml',main_n).should == expected
32
+ a.format_name(2,main_d2+'/chapter.xml',main_n).length.should == 61
33
+ end
34
+
35
+ end
36
+
37
+ it "formats file sizes for humans" do
38
+ a = App.new
39
+ a.format_size(1023).should == "1023B"
40
+ a.format_size(1024).should == "1KB"
41
+ a.format_size(1025).should == "1KB"
42
+ a.format_size(999*App::KB).should == "999KB"
43
+ a.format_size(1024*App::KB).should == "1MB"
44
+ a.format_size(3200*App::KB).should == "3MB"
45
+ a.format_size(9999*App::MB).should == "9GB"
46
+ a.format_size(1023*App::GB).should == "1023GB"
47
+ a.format_size(1024 + App::TB).should == "1TB"
48
+ a.format_size(1024 + App::PB).should == "XXL"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,72 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require_relative '../spec_helper'
3
+
4
+ module DocbookFiles
5
+ describe Docbook do
6
+
7
+ it "can cope with invalid xml files" do
8
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/no-xml.xml")
9
+ actual = dbf.list()
10
+ actual.class.should == DocbookFiles::FileData
11
+ actual.name.should == "no-xml.xml"
12
+ actual.size.should == 15
13
+ actual.docbook.should be_false
14
+ end
15
+
16
+ it "finds namespace, DocBookness, version" do
17
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/bookxi.xml")
18
+ actual = dbf.list()
19
+ actual.namespace.should == "http://docbook.org/ns/docbook"
20
+ actual.docbook.should be_true
21
+ actual.version.should == "5.0"
22
+ end
23
+
24
+ it "finds no namespace, DocBookness, version" do
25
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/no-ns.xml")
26
+ actual = dbf.list()
27
+ actual.namespace.should be_empty
28
+ actual.docbook.should be_false
29
+ actual.version.should be_empty
30
+ end
31
+
32
+ it "finds a tag" do
33
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/bookxi.xml")
34
+ actual = dbf.list()
35
+ actual.tag.should == "book"
36
+ end
37
+
38
+ it "lists" do
39
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/bookxi.xml")
40
+ actual = dbf.list()
41
+ expected = [{:type => :main, :name=>"bookxi.xml"},
42
+ [{:type => :inc, :name=>"chapter2xi.xml"}, [{:type => :inc, :name=>"section1xi.xml"}]],
43
+ [{:type => :inc, :name=>"chapter3xi.xml"}], [{:type => :inc, :name=>"chapter4xi.xml"}]]
44
+ actual.names.should == expected
45
+ end
46
+
47
+ it "lists as a table" do
48
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/bookxi.xml")
49
+ actual = dbf.list_as_table([:name])
50
+ expected = [{:type => :main, :name=>"bookxi.xml", :level=>0},
51
+ {:type => :inc, :name=>"chapter2xi.xml", :level=>1},
52
+ {:type => :inc, :name=>"section1xi.xml", :level=>2},
53
+ {:type => :inc, :name=>"chapter3xi.xml", :level=>1},
54
+ {:type => :inc, :name=>"chapter4xi.xml", :level=>1}]
55
+ actual.should == expected
56
+ end
57
+
58
+ it "finds referenced files" do
59
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/refs/book-simple.xml")
60
+ actual = dbf.list()
61
+ actual.refs.map{|r|r.name}.should == ["orange.png","orange.jpeg"]
62
+ end
63
+
64
+ it "marks non-existing references" do
65
+ dbf = DocbookFiles::Docbook.new("spec/fixtures/refs/book-simple-err.xml")
66
+ actual = dbf.list()
67
+ actual.refs.map{|r|r.name}.should == ["orange.png","orange.jpeg"]
68
+ actual.refs.map{|r|r.exists}.should == [true,false]
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,78 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require_relative '../spec_helper'
3
+ require 'time'
4
+
5
+ module DocbookFiles
6
+ describe FileData do
7
+
8
+ it "calculates a checksum" do
9
+ f = FileData.new("spec/fixtures/bookxi.xml")
10
+ f.checksum.should == "7d240e7a084c16665ac59e5b927acd6a06953897"
11
+ end
12
+
13
+ it "finds a XML MIME type" do
14
+ f = FileData.new("spec/fixtures/bookxi.xml")
15
+ f.mime.should == "application/xml"
16
+ end
17
+
18
+ it "finds a plain text MIME type" do
19
+ pending("different MIME lib?") do
20
+ f = FileData.new("spec/fixtures/no-xml.xml")
21
+ f.mime.should_not == "application/xml"
22
+ end
23
+ end
24
+
25
+ it "converts a single FileData instance to a hash" do
26
+ f = FileData.new("spec/fixtures/bookxi.xml")
27
+ actual = f.to_hash([:name,:mime,:size],FileData::TYPE_MAIN)
28
+ actual.should == {:type => :main, :name=>"bookxi.xml", :mime=>"application/xml", :size=>481}
29
+ actual = f.to_hash([:name, :full_name, :namespace, :docbook, :version, :tag, :parent, :exists, :ts, :size, :checksum, :mime],FileData::TYPE_MAIN)
30
+ expected = {:type => :main, :name=>"bookxi.xml",
31
+ :full_name=>File.expand_path(".")+"/spec/fixtures/bookxi.xml",
32
+ :namespace=>"", :docbook=>false, :version=>"", :tag=>"", :parent=>nil, :exists=>true,
33
+ :ts=>Time.parse("2011-10-06 20:45:01 +0200"), :size=>481,
34
+ :checksum=>"7d240e7a084c16665ac59e5b927acd6a06953897", :mime=>"application/xml"}
35
+ actual.should == expected
36
+ end
37
+
38
+ it "converts a FileData tree to an array of hashes" do
39
+ f1 = FileData.new("spec/fixtures/bookxi.xml")
40
+ f2 = FileData.new("spec/fixtures/chapter2xi.xml")
41
+ f3 = FileData.new("spec/fixtures/chapter3xi.xml")
42
+ f1.includes = [f2]
43
+ f2.includes = [f3]
44
+ expected = [{:type => :main, :name=>"bookxi.xml", :mime=>"application/xml", :size=>481},
45
+ [{:type => :inc, :name=>"chapter2xi.xml", :mime=>"application/xml", :size=>366},
46
+ [{:type => :inc, :name=>"chapter3xi.xml", :mime=>"application/xml", :size=>286}]]]
47
+ actual = f1.traverse([:name,:mime,:size],FileData::TYPE_MAIN)
48
+ actual.should == expected
49
+ end
50
+
51
+ it "converts a FileData tree to a table of hashes" do
52
+ f1 = FileData.new("spec/fixtures/bookxi.xml")
53
+ f2 = FileData.new("spec/fixtures/chapter2xi.xml")
54
+ f3 = FileData.new("spec/fixtures/chapter3xi.xml")
55
+ f1.includes = [f2]
56
+ f2.includes = [f3]
57
+ expected = [{:type => :main, :name=>"bookxi.xml", :mime=>"application/xml", :size=>481, :level=>0},
58
+ {:type => :inc, :name=>"chapter2xi.xml", :mime=>"application/xml", :size=>366, :level=>1},
59
+ {:type => :inc, :name=>"chapter3xi.xml", :mime=>"application/xml", :size=>286, :level=>2}]
60
+ actual = f1.traverse_as_table([:name,:mime,:size])
61
+ actual.should == expected
62
+ end
63
+
64
+ it "finds non-existing files" do
65
+ f1 = FileData.new("spec/fixtures/bookxi.xml")
66
+ f2 = FileData.new("spec/fixtures/chapter2xi.xml",".",f1)
67
+ f3 = FileData.new("spec/fixtures/chapter3xi.xml",".",f2)
68
+ f5 = FileData.new("spec/fixtures/non-existing.xml",".",f2)
69
+ f1.includes = [f2]
70
+ f2.includes = [f3,f5]
71
+ expected = [{:type => :inc, :name=>"non-existing.xml", :parent=>"chapter2xi.xml"}]
72
+ actual = f1.find_non_existing_files()
73
+ actual.should == expected
74
+ end
75
+
76
+ end
77
+ end
78
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -20,6 +20,9 @@
20
20
  <imageobject>
21
21
  <imagedata align="right" width="6cm" format="JPEG" fileref="img/orange.jpeg"/>
22
22
  </imageobject>
23
+ <imageobject>
24
+ <imagedata align="right" width="6cm" format="SVG" fileref="img/ship.svg"/>
25
+ </imageobject>
23
26
  <textobject>
24
27
  <para>
25
28
  Textobject inside a mediaboject.
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="21 19 416 350" width="416pt" height="350pt"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>2011-10-11 18:52Z</dc:date><!-- Produced by OmniGraffle Professional 5.3.2 --></metadata><defs><filter id="Shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="3.488"/><feOffset in="blur" result="offset" dx="0" dy="4"/><feFlood flood-color="black" flood-opacity=".75" result="flood"/><feComposite in="flood" in2="offset" operator="in"/></filter></defs><g stroke="none" stroke-opacity="1" stroke-dasharray="none" fill="none" fill-opacity="1"><title>Arbeitsfläche 1</title><g><title>Ebene 1</title><g><use xl:href="#id1_Graphic" filter="url(#Shadow)"/></g><g id="id1_Graphic"><rect x="32.96875" y="26" width="392.7461" height="327.3711" fill="white"/><rect x="32.96875" y="26" width="392.7461" height="327.3711" stroke="black" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/></g></g></g></svg>
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
1
2
 
2
3
  require File.expand_path(
3
4
  File.join(File.dirname(__FILE__), %w[.. lib docbook_files]))
4
5
 
5
- Spec::Runner.configure do |config|
6
+ RSpec.configure do |config|
6
7
  # == Mock Framework
7
8
  #
8
9
  # RSpec uses it's own mocking framework by default. If you prefer to
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docbook_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-10 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libxml-ruby
16
- requirement: &2160079640 !ruby/object:Gem::Requirement
16
+ requirement: &2167031960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2160079640
24
+ version_requirements: *2167031960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: term-ansicolor
27
- requirement: &2160076200 !ruby/object:Gem::Requirement
27
+ requirement: &2167031020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2160076200
35
+ version_requirements: *2167031020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: wand
38
- requirement: &2160074160 !ruby/object:Gem::Requirement
38
+ requirement: &2167030100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2160074160
46
+ version_requirements: *2167030100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bones
49
- requirement: &2152251960 !ruby/object:Gem::Requirement
49
+ requirement: &2167029100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 3.7.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152251960
57
+ version_requirements: *2167029100
58
58
  description: docbook_files lists and checks all files related to a DocBook writing
59
59
  project.
60
60
  email: dev@textmulch.de
@@ -65,40 +65,43 @@ extra_rdoc_files:
65
65
  - History.txt
66
66
  - bin/docbook_files
67
67
  files:
68
- - .DS_Store
69
- - .gitignore
68
+ - About.org
70
69
  - Gemfile
71
70
  - Gemfile.lock
71
+ - Guardfile
72
72
  - History.txt
73
73
  - README.md
74
74
  - Rakefile
75
75
  - bin/docbook_files
76
76
  - lib/docbook_files.rb
77
+ - lib/docbook_files/app.rb
77
78
  - lib/docbook_files/docbook.rb
78
79
  - lib/docbook_files/file_data.rb
80
+ - spec/docbook_files/app_spec.rb
81
+ - spec/docbook_files/docbook_spec.rb
82
+ - spec/docbook_files/file_data_spec.rb
79
83
  - spec/docbook_files_spec.rb
84
+ - spec/fixtures/.DS_Store
85
+ - spec/fixtures/book-nonexisting.xml
86
+ - spec/fixtures/bookxi.xml
87
+ - spec/fixtures/c4/chapter4xi.xml
88
+ - spec/fixtures/chapter2xi.xml
89
+ - spec/fixtures/chapter3xi.xml
90
+ - spec/fixtures/no-ns.xml
91
+ - spec/fixtures/no-xml.xml
92
+ - spec/fixtures/refs/.DS_Store
93
+ - spec/fixtures/refs/book-simple-err.xml
94
+ - spec/fixtures/refs/book-simple.xml
95
+ - spec/fixtures/refs/bookxi.xml
96
+ - spec/fixtures/refs/c4/chapter4xi.xml
97
+ - spec/fixtures/refs/chapter2xi.xml
98
+ - spec/fixtures/refs/chapter3xi.xml
99
+ - spec/fixtures/refs/img/orange.jpeg
100
+ - spec/fixtures/refs/img/orange.png
101
+ - spec/fixtures/refs/img/ship.svg
102
+ - spec/fixtures/refs/section1xi.xml
103
+ - spec/fixtures/section1xi.xml
80
104
  - spec/spec_helper.rb
81
- - test/.DS_Store
82
- - test/docbook_files/test_docbook.rb
83
- - test/docbook_files/test_file_data.rb
84
- - test/fixtures/book-nonexisting.xml
85
- - test/fixtures/bookxi.xml
86
- - test/fixtures/c4/chapter4xi.xml
87
- - test/fixtures/chapter2xi.xml
88
- - test/fixtures/chapter3xi.xml
89
- - test/fixtures/no-ns.xml
90
- - test/fixtures/no-xml.xml
91
- - test/fixtures/refs/book-simple-err.xml
92
- - test/fixtures/refs/book-simple.xml
93
- - test/fixtures/refs/bookxi.xml
94
- - test/fixtures/refs/c4/chapter4xi.xml
95
- - test/fixtures/refs/chapter2xi.xml
96
- - test/fixtures/refs/chapter3xi.xml
97
- - test/fixtures/refs/img/orange.jpeg
98
- - test/fixtures/refs/img/orange.png
99
- - test/fixtures/refs/section1xi.xml
100
- - test/fixtures/section1xi.xml
101
- - test/test_docbook_files.rb
102
105
  - version.txt
103
106
  homepage: http://github.com/rvolz/docbook_files/
104
107
  licenses: []
@@ -122,11 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
125
  version: '0'
123
126
  requirements: []
124
127
  rubyforge_project: docbook_files
125
- rubygems_version: 1.8.10
128
+ rubygems_version: 1.8.11
126
129
  signing_key:
127
130
  specification_version: 3
128
131
  summary: docbook_files lists and checks all files related to a DocBook writing project.
129
- test_files:
130
- - test/docbook_files/test_docbook.rb
131
- - test/docbook_files/test_file_data.rb
132
- - test/test_docbook_files.rb
132
+ test_files: []
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.*~
2
- .DS_Store
3
- coverage
4
- rdoc
5
- doc
6
- pkg
7
- #*.*
@@ -1,76 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'minitest/spec'
3
- require 'turn'
4
- require "docbook_files"
5
-
6
- MiniTest::Unit.use_natural_language_case_names = true
7
-
8
- module DocbookFiles
9
- describe Docbook do
10
-
11
- it "can cope with invalid xml files" do
12
- dbf = DocbookFiles::Docbook.new("test/fixtures/no-xml.xml")
13
- actual = dbf.list()
14
- actual.must_be_kind_of(DocbookFiles::FileData)
15
- actual.name.must_equal("no-xml.xml")
16
- actual.size.must_equal(15)
17
- actual.docbook.must_equal(false)
18
- end
19
-
20
- it "finds namespace, DocBookness, version" do
21
- dbf = DocbookFiles::Docbook.new("test/fixtures/bookxi.xml")
22
- actual = dbf.list()
23
- actual.namespace.must_equal("http://docbook.org/ns/docbook")
24
- actual.docbook.must_equal(true)
25
- actual.version.must_equal("5.0")
26
- end
27
-
28
- it "finds no namespace, DocBookness, version" do
29
- dbf = DocbookFiles::Docbook.new("test/fixtures/no-ns.xml")
30
- actual = dbf.list()
31
- actual.namespace.must_equal("")
32
- actual.docbook.must_equal(false)
33
- actual.version.must_equal("")
34
- end
35
-
36
- it "finds a tag" do
37
- dbf = DocbookFiles::Docbook.new("test/fixtures/bookxi.xml")
38
- actual = dbf.list()
39
- actual.tag.must_equal("book")
40
- end
41
-
42
- it "lists" do
43
- dbf = DocbookFiles::Docbook.new("test/fixtures/bookxi.xml")
44
- actual = dbf.list()
45
- expected = [{:name=>"bookxi.xml"},
46
- [{:name=>"chapter2xi.xml"}, [{:name=>"section1xi.xml"}]],
47
- [{:name=>"chapter3xi.xml"}], [{:name=>"chapter4xi.xml"}]]
48
- actual.names.must_equal(expected)
49
- end
50
-
51
- it "lists as a table" do
52
- dbf = DocbookFiles::Docbook.new("test/fixtures/bookxi.xml")
53
- actual = dbf.list_as_table([:name])
54
- expected = [{:name=>"bookxi.xml", :level=>0},
55
- {:name=>"chapter2xi.xml", :level=>1},
56
- {:name=>"section1xi.xml", :level=>2},
57
- {:name=>"chapter3xi.xml", :level=>1},
58
- {:name=>"chapter4xi.xml", :level=>1}]
59
- actual.must_equal(expected)
60
- end
61
-
62
- it "finds referenced files" do
63
- dbf = DocbookFiles::Docbook.new("test/fixtures/refs/book-simple.xml")
64
- actual = dbf.list()
65
- actual.refs.map{|r|r.name}.must_equal(["orange.png","orange.jpeg"])
66
- end
67
-
68
- it "marks non-existing references" do
69
- dbf = DocbookFiles::Docbook.new("test/fixtures/refs/book-simple-err.xml")
70
- actual = dbf.list()
71
- actual.refs.map{|r|r.name}.must_equal(["orange.png","orange.jpeg"])
72
- actual.refs.map{|r|r.exists}.must_equal([true,false])
73
- end
74
-
75
- end
76
- end
@@ -1,83 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'minitest/spec'
3
- require 'turn'
4
- require "docbook_files"
5
- require 'date'
6
-
7
- MiniTest::Unit.use_natural_language_case_names = true
8
-
9
- module DocbookFiles
10
- describe FileData do
11
- it "initializes" do
12
- end
13
-
14
- it "calculates a checksum" do
15
- f = FileData.new("test/fixtures/bookxi.xml")
16
- f.checksum.must_equal("7d240e7a084c16665ac59e5b927acd6a06953897")
17
- end
18
-
19
- it "finds a XML MIME type" do
20
- f = FileData.new("test/fixtures/bookxi.xml")
21
- f.mime.must_equal("application/xml")
22
- end
23
-
24
- it "finds a plain text MIME type" do
25
- skip "Different MIME lib?"
26
- f = FileData.new("test/fixtures/no-xml.xml")
27
- f.mime.wont_equal("application/xml")
28
- end
29
-
30
- it "converts a single FileData instance to a hash" do
31
- f = FileData.new("test/fixtures/bookxi.xml")
32
- actual = f.to_hash([:name,:mime,:size])
33
- actual.must_equal({:name=>"bookxi.xml", :mime=>"application/xml", :size=>481})
34
- actual = f.to_hash()
35
- expected = {:name=>"bookxi.xml",
36
- :full_name=>"/Users/rv/Documents/Projekte/docbook_files/test/fixtures/bookxi.xml",
37
- :namespace=>"", :docbook=>false, :version=>"", :tag=>"", :parent=>nil, :exists=>true,
38
- :ts=>Time.parse("2011-10-06 20:45:01 +0200"), :size=>481,
39
- :checksum=>"7d240e7a084c16665ac59e5b927acd6a06953897", :mime=>"application/xml", :refs => []}
40
- actual.must_equal(expected)
41
- end
42
-
43
- it "converts a FileData tree to an array of hashes" do
44
- f1 = FileData.new("test/fixtures/bookxi.xml")
45
- f2 = FileData.new("test/fixtures/chapter2xi.xml")
46
- f3 = FileData.new("test/fixtures/chapter3xi.xml")
47
- f1.includes = [f2]
48
- f2.includes = [f3]
49
- expected = [{:name=>"bookxi.xml", :mime=>"application/xml", :size=>481},
50
- [{:name=>"chapter2xi.xml", :mime=>"application/xml", :size=>366},
51
- [{:name=>"chapter3xi.xml", :mime=>"application/xml", :size=>286}]]]
52
- actual = f1.traverse([:name,:mime,:size])
53
- actual.must_equal(expected)
54
- end
55
-
56
- it "converts a FileData tree to a table of hashes" do
57
- f1 = FileData.new("test/fixtures/bookxi.xml")
58
- f2 = FileData.new("test/fixtures/chapter2xi.xml")
59
- f3 = FileData.new("test/fixtures/chapter3xi.xml")
60
- f1.includes = [f2]
61
- f2.includes = [f3]
62
- expected = [{:name=>"bookxi.xml", :mime=>"application/xml", :size=>481, :level=>0},
63
- {:name=>"chapter2xi.xml", :mime=>"application/xml", :size=>366, :level=>1},
64
- {:name=>"chapter3xi.xml", :mime=>"application/xml", :size=>286, :level=>2}]
65
- actual = f1.traverse_as_table([:name,:mime,:size])
66
- actual.must_equal(expected)
67
- end
68
-
69
- it "finds non-existing files" do
70
- f1 = FileData.new("test/fixtures/bookxi.xml")
71
- f2 = FileData.new("test/fixtures/chapter2xi.xml",".",f1)
72
- f3 = FileData.new("test/fixtures/chapter3xi.xml",".",f2)
73
- f5 = FileData.new("test/fixtures/non-existing.xml",".",f2)
74
- f1.includes = [f2]
75
- f2.includes = [f3,f5]
76
- expected = [{:name=>"non-existing.xml", :parent=>"chapter2xi.xml"}]
77
- actual = f1.find_non_existing_files()
78
- actual.must_equal(expected)
79
- end
80
-
81
- end
82
- end
83
-
@@ -1,6 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'minitest/spec'
3
- require 'minitest/autorun'
4
- require "docbook_files"
5
- require 'turn'
6
-