odf_thumb 0.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84ab44e70b9805acfa547ee2662de0a5681b1fea
4
+ data.tar.gz: c133f131d993b0d1e54c52ecae0df20e8711b63d
5
+ SHA512:
6
+ metadata.gz: e23df1cf76bb9722f8feb82d91d9c351164827e9f01e652737181baa034218013de436e1347b3647333a47bb37e93b981f66c51d16cdebea7d0814429143413d
7
+ data.tar.gz: 213531b6bad4c864e8761b2c7544ee2e31d58e803ae7ab3aa690d9dc8974d30cebf3e93c14e3ce6897382a8b1f90be3f1ce4e44cfe655d3103798f06451994c6
@@ -0,0 +1 @@
1
+ /pkg/
@@ -0,0 +1,3 @@
1
+ # v0.1.0 - 2016-05-26 - Initial release
2
+
3
+ Provides initial feature set, extracting thumbnails for OpenDocument files.
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at schmidt@nach-vorne.eu. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in odf_thumb.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ odf_thumb (0.1.0)
5
+ rubyzip (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.8.4)
11
+ rake (10.5.0)
12
+ rubyzip (1.2.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.11)
19
+ minitest (~> 5.0)
20
+ odf_thumb!
21
+ rake (~> 10.0)
22
+
23
+ BUNDLED WITH
24
+ 1.12.3
@@ -0,0 +1,106 @@
1
+ # OdfThumb
2
+
3
+ This gem extracts existing thumbnail files from OpenDocument files, i.e. files
4
+ created with OpenOffice or LibreOffice.
5
+
6
+ It cannot be guaranteed, that such a file exists. Most desktop applications will
7
+ create and update such a file, while converters, export tools and command line
8
+ utilities might not.
9
+
10
+ According to
11
+ [Wikipedia](https://en.wikipedia.org/w/index.php?title=OpenDocument_technical_specification&oldid=695208884),
12
+ the thumbnail
13
+
14
+ > should be a representation of the first page, first sheet, etc. of the
15
+ > document. The required size for the thumbnails is 128x128 pixel. In order to
16
+ > conform to the [Thumbnail Managing
17
+ > Standard](http://standards.freedesktop.org/thumbnail-spec/latest/x142.html#AEN144)
18
+ > (TMS) at www.freedesktop.org, thumbnails must be saved as 8bit, non-interlaced
19
+ > PNG image with full alpha transparency.
20
+
21
+
22
+
23
+ ## Alternative approaches
24
+
25
+ If these properties do not meet your requirements, try creating a thumbnail
26
+ by making use LibreOffice's conversion capabilities. E.g. convert your document
27
+ to a PNG and create a thumbnail based on that. The following command will create
28
+ a PNG called `Example.png` based on the first page of a OpenDocument text file.
29
+
30
+ soffice --headless --convert-to png Example.odt
31
+
32
+
33
+
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ ```ruby
39
+ gem 'odf_thumb'
40
+ ```
41
+
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install odf_thumb
49
+
50
+
51
+
52
+ ## Command line usage
53
+
54
+ OdfThumb comes with a command line tool
55
+
56
+ ```
57
+ # Creates a path/to/source.png
58
+ odf_thumb path/to/source.odt
59
+
60
+ # Creates a path/to/target/thumb.png
61
+ odf_thumb path/to/source.odt -o path/to/target/thumb.png
62
+
63
+ # Exits with error code 1 if the given file did not contain a thumbnail file
64
+ odf_thumb other_file.txt
65
+ echo $? # => 1
66
+ ```
67
+
68
+
69
+
70
+ ## API usage
71
+
72
+ ```ruby
73
+ doc = OdfThumb::Document.new("source.odt")
74
+
75
+ # Returns true if document contains thumbnail file
76
+ doc.has_thumb?
77
+
78
+ # Returns thumbnail as binary string, nil if has_thumb? == false
79
+ doc.thumbnail
80
+
81
+ # Write thumbnail to given path, does nothing if has_thumb? == false
82
+ doc.write_thumbnail_to("thumb.odt")
83
+ ```
84
+
85
+
86
+
87
+ ## Development
88
+
89
+ After checking out the repo, run `bundle install` to install dependencies. Then,
90
+ run `rake test` to run the tests. You can also run `bin/console` for an
91
+ interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To
94
+ release a new version, update the version number in `version.rb`, and then run
95
+ `bundle exec rake release`, which will create a git tag for the version, push
96
+ git commits and tags, and push the `.gem` file to
97
+ [rubygems.org](https://rubygems.org).
98
+
99
+
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at
104
+ https://github.com/schmidt/odf_thumb. This project is intended to be a safe,
105
+ welcoming space for collaboration, and contributors are expected to adhere to
106
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "odf_thumb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "irb"
10
+ IRB.start
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'odf_thumb'
5
+
6
+ options = {}
7
+ parser = OptionParser.new do |opts|
8
+ opts.banner = "Usage: odt_thumb [options] source.odt"
9
+
10
+ opts.on("-o", "--outfile target.png", "Write PNG to given path") do |target|
11
+ options[:target] = target
12
+ end
13
+
14
+ opts.on("-h", "--help", "Show this message") do
15
+ puts opts
16
+ exit
17
+ end
18
+ end
19
+
20
+ parser.parse!
21
+
22
+ if ARGV.size != 1
23
+ puts parser
24
+ exit
25
+ end
26
+
27
+ doc = begin
28
+ OdfThumb::Document.new(ARGV[0])
29
+ rescue ArgumentError
30
+ warn "File not readable - #{ARGV[0]}"
31
+ exit 2
32
+ end
33
+
34
+ unless doc.has_thumb?
35
+ warn "File does not contain thumbnail."
36
+ exit 1
37
+ end
38
+
39
+ target = if options[:target]
40
+ options[:target]
41
+ else
42
+ File.join(File.dirname(doc.source), File.basename(doc.source, ".*") + ".png")
43
+ end
44
+
45
+ doc.write_thumbnail_to(target)
46
+ puts "Thumbnail written to #{target}"
@@ -0,0 +1,7 @@
1
+ require "zip"
2
+
3
+ module OdfThumb
4
+ end
5
+
6
+ require "odf_thumb/version"
7
+ require "odf_thumb/document"
@@ -0,0 +1,35 @@
1
+ class OdfThumb::Document
2
+ attr_reader :source
3
+
4
+ def initialize(source)
5
+ unless File.readable? source
6
+ raise ArgumentError.new "Cannot read source file"
7
+ end
8
+
9
+ @source = source
10
+ end
11
+
12
+ def has_thumb?
13
+ Zip::File.open(source) do |file|
14
+ !!file.find_entry("Thumbnails/thumbnail.png")
15
+ end
16
+ rescue Zip::Error
17
+ false
18
+ end
19
+
20
+ def thumbnail
21
+ Zip::File.open(source) do |file|
22
+ file.read("Thumbnails/thumbnail.png")
23
+ end
24
+ rescue Zip::Error, Errno::ENOENT
25
+ nil
26
+ end
27
+
28
+ def write_thumbnail_to(target)
29
+ Zip::File.open(source) do |file|
30
+ file.extract("Thumbnails/thumbnail.png", target)
31
+ end
32
+ rescue Zip::Error, Errno::ENOENT
33
+ nil
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module OdfThumb
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'odf_thumb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "odf_thumb"
8
+ spec.version = OdfThumb::VERSION
9
+ spec.authors = ["Gregor Schmidt"]
10
+ spec.email = ["schmidt@nach-vorne.eu"]
11
+
12
+ spec.summary = %q{odf_thumb extracts existing thumbnail files from OpenDocument files.}
13
+ spec.homepage = "https://github.com/schmidt/odf_thumb"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.executables = ["odf_thumb"]
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "rubyzip", "~> 1.0"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odf_thumb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregor Schmidt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - schmidt@nach-vorne.eu
72
+ executables:
73
+ - odf_thumb
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CHANGELOG.txt
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/odf_thumb
86
+ - lib/odf_thumb.rb
87
+ - lib/odf_thumb/document.rb
88
+ - lib/odf_thumb/version.rb
89
+ - odf_thumb.gemspec
90
+ homepage: https://github.com/schmidt/odf_thumb
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: odf_thumb extracts existing thumbnail files from OpenDocument files.
113
+ test_files: []