docx_generator 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f32f9709d0ce194476a9904032ce4e06130f61e
4
- data.tar.gz: 9b3dc472bb8ad9a5d4c080e29806c242507391d7
3
+ metadata.gz: 9bc3cbf1c52c84cee2dd817473aa0a8882dcf549
4
+ data.tar.gz: ef2326f448ea1e8c8fad204e93cafe18df284a1e
5
5
  SHA512:
6
- metadata.gz: 353b0025fae8f672ca3077f0c26a2755019d0d24494d1eac247a68e3c63451621ae18d7e2ea54bcb03101f35f35196f4605760f1ccf376e0c6a2f8c571f87a65
7
- data.tar.gz: ae2034b6683efba44a5cdfccafb8229d2f31476131a9b6703739c09e47c51da09c85f9bd35ee9882853093d3b0d2353c7a2ff80648d7b6b31596b11c0fce75a6
6
+ metadata.gz: 2ffef6f8f98d48635e29c18438696bf5c688cf90b1d37762b3632215ffe496f27e7ae5f36ce9fbcc81a74c660194f8dc6f8895ec56cb0f7f96c698f815b34edd
7
+ data.tar.gz: cdb04b317c6715a0ce40ed8172e916a9812c7377ee665bb08252d53c1f75a0eddde2d77716dd3b54aec32a8be630a4c064920314f2c0b0f7b71876ce94000d6a
data/.gitignore CHANGED
@@ -1,18 +1,18 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.docx
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.docx
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in docx_generator.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ ruby "2.0.0"
4
+
5
+ # Specify your gem's dependencies in docx_generator.gemspec
6
+ gemspec
data/Guardfile CHANGED
@@ -1,11 +1,11 @@
1
- guard 'bundler' do
2
- watch('Gemfile')
3
- watch(/^.+\.gemspec/)
4
- end
5
-
6
- guard :rspec, cli: "--color" do
7
- watch(%r{^spec/.+_spec\.rb$})
8
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
- watch('spec/spec_helper.rb') { "spec" }
10
- end
11
-
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec, cli: "--color" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
11
+
@@ -1,22 +1,22 @@
1
- Copyright (c) 2013 Antoine Proulx
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2013 Antoine Proulx
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,41 +1,41 @@
1
- # DocxGenerator
2
-
3
- A gem to generate docx files.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'docx_generator'
11
- ```
12
-
13
- And then execute:
14
-
15
- ```
16
- $ bundle
17
- ```
18
-
19
- Or install it yourself as:
20
-
21
- ```
22
- $ gem install docx_generator
23
- ```
24
-
25
- ## Usage
26
-
27
- DocxGenerator can be used with blocks or without. See `examples/basic_document_with_block.rb` and `examples/basic_document_without_block.rb` for the basic usage.
28
-
29
- ## Documentation
30
-
31
- The documentation can be found at [Rubydoc.info](http://rubydoc.info/github/magicienap/docx_generator/frames).
32
-
33
- ## Contributing
34
-
35
- 1. Fork it
36
- 2. Create your feature branch (`git checkout -b my-new-feature`)
37
- 3. Commit your changes (`git commit -am 'Add some feature'`)
38
- 4. Push to the branch (`git push origin my-new-feature`)
39
- 5. Create new Pull Request
40
-
41
- [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/557c5048ed09993a48f60e0aa0869ab3 "githalytics.com")](http://githalytics.com/magicienap/docx_generator)
1
+ # DocxGenerator
2
+
3
+ A gem to generate docx files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'docx_generator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install docx_generator
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ DocxGenerator can be used with blocks or without. See `examples/basic_document_with_block.rb` and `examples/basic_document_without_block.rb` for the basic usage.
28
+
29
+ ## Documentation
30
+
31
+ The documentation can be found at [Rubydoc.info](http://rubydoc.info/github/magicienap/docx_generator/frames).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
40
+
41
+ [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/557c5048ed09993a48f60e0aa0869ab3 "githalytics.com")](http://githalytics.com/magicienap/docx_generator)
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task default: :spec
7
- task test: :spec
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -1,36 +1,36 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'docx_generator/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "docx_generator"
8
- spec.version = DocxGenerator::VERSION
9
- spec.authors = ["Antoine Proulx"]
10
- spec.email = ["proulx.antoine@gmail.com"]
11
- spec.description = %q{A gem to generate docx files.}
12
- spec.summary = %q{A gem to generate docx files.}
13
- spec.homepage = "http://magicienap.github.io/docx_generator"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
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_runtime_dependency "rubyzip"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "guard"
27
- spec.add_development_dependency "guard-bundler"
28
- spec.add_development_dependency "guard-rspec"
29
- spec.add_development_dependency "libnotify"
30
- spec.add_development_dependency "yard"
31
-
32
- if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
33
- spec.add_development_dependency "wdm"
34
- spec.add_development_dependency "win32console"
35
- end
36
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docx_generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "docx_generator"
8
+ spec.version = DocxGenerator::VERSION
9
+ spec.authors = ["Antoine Proulx"]
10
+ spec.email = ["proulx.antoine@gmail.com"]
11
+ spec.description = %q{A gem to generate docx files.}
12
+ spec.summary = %q{A gem to generate docx files.}
13
+ spec.homepage = "http://magicienap.github.io/docx_generator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency "rubyzip", '>= 1'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "guard"
27
+ spec.add_development_dependency "guard-bundler"
28
+ spec.add_development_dependency "guard-rspec"
29
+ spec.add_development_dependency "libnotify"
30
+ spec.add_development_dependency "yard"
31
+
32
+ if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
33
+ spec.add_development_dependency "wdm"
34
+ spec.add_development_dependency "win32console"
35
+ end
36
+ end
@@ -1,37 +1,41 @@
1
- require 'docx_generator'
2
-
3
- DocxGenerator::DSL::Document.new("basic_paragraph") do |doc|
4
- doc.paragraph do |par|
5
- par.alignment :center
6
- par.text "Title", underline: { style: "double" }, size: 20
7
- # par.newline
8
- end
9
-
10
- doc.paragraph do |par|
11
- par.text "Simple string of text and"
12
- par.text "some formatted text" do |t|
13
- t.bold true
14
- t.italics true
15
- t.underline style: "single"
16
- end
17
- end
18
-
19
- doc.paragraph do |par|
20
- par.text "Antoine", bold: true
21
- par.text "How are you today?"
22
- end
23
-
24
- doc.paragraph do |par|
25
- par.text "John", bold: true
26
- par.text "(whispering)", bold: true, italics: true
27
- par.text "How are you today?"
28
- end
29
-
30
- doc.paragraph(alignment: :center) do |par|
31
- par.text "A simple chemical formula: CO"
32
- par.no_space
33
- par.text "2", subscript: true
34
- end
35
-
36
- doc.save
1
+ require 'docx_generator'
2
+
3
+ DocxGenerator::DSL::Document.new("basic_paragraph") do |doc|
4
+ doc.paragraph do |par|
5
+ par.alignment :center
6
+ par.text "Title" do |t|
7
+ t.underline style: "double"
8
+ t.size 20
9
+ t.caps true
10
+ end
11
+ par.newline
12
+ end
13
+
14
+ doc.paragraph do |par|
15
+ par.text "Simple string of text and"
16
+ par.text "some formatted text" do |t|
17
+ t.bold true
18
+ t.italics true
19
+ t.underline style: "single"
20
+ end
21
+ end
22
+
23
+ doc.paragraph do |par|
24
+ par.text "Antoine", bold: true, small_caps: true
25
+ par.text "How are you today?"
26
+ end
27
+
28
+ doc.paragraph do |par|
29
+ par.text "John", bold: true, small_caps: true
30
+ par.text "(whispering)", bold: true, italics: true
31
+ par.text "How are you today?"
32
+ end
33
+
34
+ doc.paragraph(alignment: :center) do |par|
35
+ par.text "A simple chemical formula: CO"
36
+ par.no_space
37
+ par.text "2", subscript: true
38
+ end
39
+
40
+ doc.save
37
41
  end
@@ -1,10 +1,10 @@
1
- require 'docx_generator'
2
- include DocxGenerator::DSL
3
-
4
- doc = Document.new("basic_paragraph")
5
- doc.add Paragraph.new(alignment: "center").add(Text.new("Title", underline: { style: "double" }, size: 20))#, DocxGenerator::Word::Extensions::Newline.new)
6
- doc.add Paragraph.new.add(Text.new("Simple string of text and"), Text.new("some formatted text"), bold: true, italics: true, underline: { style: "single" })
7
- doc.add Paragraph.new.add(Text.new("Antoine", bold: true), Text.new("How are you today?"))
8
- doc.add Paragraph.new.add(Text.new("John", bold: true), Text.new("(whispering)", bold: true, italics: true), Text.new("How are you today"))
9
- doc.add Paragraph.new(alignment: "center").add(Text.new("A simple chemical formula: CO"), DocxGenerator::Word::Extensions::NoSpace.new, Text.new("2", subscript: true))
1
+ require 'docx_generator'
2
+ include DocxGenerator::DSL
3
+
4
+ doc = Document.new("basic_paragraph")
5
+ doc.add Paragraph.new(alignment: "center").add(Text.new("Title", underline: { style: "double" }, size: 20, caps: true), DocxGenerator::Word::Extensions::Newline.new)
6
+ doc.add Paragraph.new.add(Text.new("Simple string of text and"), Text.new("some formatted text"), bold: true, italics: true, underline: { style: "single" })
7
+ doc.add Paragraph.new.add(Text.new("Antoine", bold: true, small_caps: true), Text.new("How are you today?"))
8
+ doc.add Paragraph.new.add(Text.new("John", bold: true, small_caps: true), Text.new("(whispering)", bold: true, italics: true), Text.new("How are you today"))
9
+ doc.add Paragraph.new(alignment: "center").add(Text.new("A simple chemical formula: CO"), DocxGenerator::Word::Extensions::NoSpace.new, Text.new("2", subscript: true))
10
10
  doc.save
@@ -0,0 +1,10 @@
1
+ class Generate < Thor
2
+
3
+ desc "word_base", "Generate the word/base.rb file with its spec file."
4
+ def word_base
5
+ require './generators/word_base'
6
+
7
+ invoke 'word_base:code'
8
+ invoke 'word_base:spec'
9
+ end
10
+ end
@@ -0,0 +1,106 @@
1
+ # I should test my code generator!
2
+ class WordBase < Thor
3
+ include Thor::Actions
4
+
5
+ # Data structure
6
+ # An array of elements
7
+ # Each element can have up to 4 properties
8
+ # - class: The name of the Ruby class (required)
9
+ # - element: The name of the element in the specification.
10
+ # If not provided, then it is the class name in lowercase
11
+ # - attributes: Wheter it should accept attributes or not (default: true)
12
+ # - content: Wheter it should accept content
13
+
14
+ @@elements = [
15
+ { class: "Document" },
16
+ { class: "Body", attributes: false },
17
+ { class: "Paragraph", element: "p" },
18
+ { class: "ParagraphProperties", element: "pPr", attributes: false },
19
+ { class: "Run", element: "r" },
20
+ { class: "RunProperties", element: "rPr", attributes: false },
21
+ { class: "Text", element: "t" },
22
+ { class: "Break", element: "br", content: false }
23
+ ]
24
+
25
+ def self.root
26
+ File.expand_path('.')
27
+ end
28
+
29
+ desc "code", "Generate the implementation code."
30
+ def code
31
+ # Change that to be a template (ERB?) with helpers
32
+ code = "# Warning: This file has been automatically generated from generator/word_base.rb.\n" +
33
+ "# It should not be edited by hand. Instead, modify the code generator.\n" +
34
+ "\n" +
35
+ "module DocxGenerator\n" +
36
+ " module Word\n"
37
+
38
+ @@elements.each do |element|
39
+ element = normalize(element)
40
+
41
+ code += " # Represent the `#{element[:element]}` element from Office Open XML specification. This class should not be used directly by the users of the library.\n" +
42
+ " class #{element[:class]} < Element\n" +
43
+ " # Create a new `#{element[:element]}` XML element.\n"
44
+
45
+ if element[:attributes]
46
+ code += " # @param attributes [Hash] The attributes of the XML element. Check the specification of the `#{element[:element]}` element for the possible attributes.\n"
47
+ end
48
+ if element[:content]
49
+ code += " # @param content [Array] An array of the children of the XML element (other XML elements).\n"
50
+ end
51
+
52
+ code += " def initialize("
53
+ code += "attributes = {}" if element[:attributes]
54
+ code += ", " if element[:attributes] && element[:content]
55
+ code += "content = []" if element[:content]
56
+ code += ")\n"
57
+
58
+ code += " super(\"#{element[:element]}\""
59
+ code += element[:attributes] ? ", attributes" : ", {}"
60
+ code += ", content" if element[:content]
61
+ code += ")\n"
62
+ code += " end\n"
63
+
64
+ code += " end\n\n"
65
+ end
66
+
67
+ code += " end\n"
68
+ code += "end"
69
+
70
+ create_file "lib/docx_generator/word/base.rb", code
71
+ end
72
+
73
+ desc "spec", "Generate the tests."
74
+ def spec
75
+ code = "require 'spec_helper'\n\n"
76
+
77
+ @@elements.each do |element|
78
+ element = normalize(element)
79
+
80
+ code += "describe DocxGenerator::Word::#{element[:class]} do\n" +
81
+ " it \"should render a #{element[:element]} element\" do\n"
82
+
83
+ code += " DocxGenerator::Word::#{element[:class]}.new.to_s.should eq('<#{element[:element]} />')\n"
84
+ if element[:content]
85
+ code += " DocxGenerator::Word::#{element[:class]}.new("
86
+ code += "{}, " if element[:attributes]
87
+ code += "[\"Text\"]).to_s.should eq('<#{element[:element]}>Text</#{element[:element]}>')\n"
88
+ end
89
+
90
+ code += " end\n" +
91
+ "end\n\n"
92
+ end
93
+
94
+ create_file "spec/docx_generator/word/base_spec.rb", code
95
+ end
96
+
97
+ private
98
+ # Add default values to the element
99
+ def normalize(element)
100
+ base = { attributes: true, content: true }
101
+ new_element = base.merge(element)
102
+ new_element[:element] = new_element[:class].downcase if new_element[:element].nil?
103
+ new_element[:element] = "w:" + new_element[:element]
104
+ return new_element
105
+ end
106
+ end