docx-html 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,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Marcus Ortiz, http://marcusortiz.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # docx-html
2
+
3
+ an extension to the `docx` gem that provides a `to_html` method for documents
4
+
5
+ ## install
6
+
7
+ gem install docx-html
8
+
9
+ ## usage
10
+
11
+ ``` ruby
12
+ require 'docx/html'
13
+
14
+ d = Docx::Document.open('test.docx')
15
+ d.to_html
16
+ ```
@@ -0,0 +1,41 @@
1
+ require 'docx'
2
+ require 'html_writer'
3
+
4
+ require 'docx/html/version'
5
+
6
+ module Docx
7
+ class Document
8
+ def to_html(options={})
9
+ HtmlWriter.new.write do |html|
10
+ html.doctype options[:doctype] || 5
11
+ html.head do |head|
12
+ head.title options[:title] || ''
13
+ end
14
+ html.body do |body|
15
+ self.each_paragraph do |paragraph|
16
+ body.p paragraph.text_runs.map{ |tr| inline_content_for(tr) }.join('')
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def inline_content_for(text_run)
25
+ inline_content = text_run.text
26
+ inline_content = wrap(inline_content, :em) if text_run.italicized?
27
+ inline_content = wrap(inline_content, :strong) if text_run.bolded?
28
+ inline_content = wrap(inline_content, :span,
29
+ {style: 'text-decoration: underline;'}) if text_run.underlined?
30
+ inline_content
31
+ end
32
+
33
+ def wrap(text, tag, attrs=nil)
34
+ html = "<#{tag.to_s}"
35
+ unless attrs.nil?
36
+ attrs.each { |k,v| html << " #{k.to_s}=\"#{v.to_s}\""}
37
+ end
38
+ html << ">#{text}</#{tag.to_s}>"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module Docx
2
+ module Html
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docx-html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcus Ortiz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: docx
16
+ requirement: &70280332704500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70280332704500
25
+ - !ruby/object:Gem::Dependency
26
+ name: html_writer
27
+ requirement: &70280332702220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70280332702220
36
+ description: convert .docx files into html
37
+ email: mportiz08@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - README.md
43
+ - LICENSE.md
44
+ - lib/docx/html/version.rb
45
+ - lib/docx/html.rb
46
+ homepage: https://github.com/mportiz08/docx-html
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ segments:
59
+ - 0
60
+ hash: 3091901995804373936
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 3091901995804373936
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: convert .docx files into html
76
+ test_files: []