mg2en 0.7.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,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <array>
5
+ <dict>
6
+ <key>AFFILIATE_ID</key>
7
+ <integer>-1</integer>
8
+ <key>COURSE_ID</key>
9
+ <integer>0</integer>
10
+ <key>COURSE_NAME</key>
11
+ <string>--</string>
12
+ <key>CUISINE_ID</key>
13
+ <integer>-1</integer>
14
+ <key>DIFFICULTY</key>
15
+ <integer>0</integer>
16
+ <key>DIRECTIONS_LIST</key>
17
+ <array/>
18
+ <key>INGREDIENTS_TREE</key>
19
+ <array/>
20
+ <key>KEYWORDS</key>
21
+ <string></string>
22
+ <key>MEASUREMENT_SYSTEM</key>
23
+ <integer>0</integer>
24
+ <key>NAME</key>
25
+ <string>Invalid URL</string>
26
+ <key>NOTE</key>
27
+ <string></string>
28
+ <key>NOTES_LIST</key>
29
+ <array/>
30
+ <key>NUTRITION</key>
31
+ <string></string>
32
+ <key>PREP_TIMES</key>
33
+ <array/>
34
+ <key>PUBLICATION_PAGE</key>
35
+ <string>http://This is Bogus</string>
36
+ <key>SERVER_ID</key>
37
+ <integer>-1</integer>
38
+ <key>SERVINGS</key>
39
+ <integer>0</integer>
40
+ <key>SOURCE</key>
41
+ <string></string>
42
+ <key>SUMMARY</key>
43
+ <string></string>
44
+ <key>TYPE</key>
45
+ <integer>102</integer>
46
+ <key>URL</key>
47
+ <string></string>
48
+ <key>YIELD</key>
49
+ <string></string>
50
+ </dict>
51
+ </array>
52
+ </plist>
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mg2en, 'generator' do
4
+ let(:parser) { Mg2en::Parser.new('spec/fixtures/1.mgourmet3') }
5
+ let(:output_file) { 'tmp/fixture.enex' }
6
+ let(:generator) { Mg2en::Generator.new(parser.recipes) }
7
+
8
+ it 'passes validation' do
9
+ XML.default_load_external_dtd = false
10
+ generator.write(output_file)
11
+ dtd = XML::Dtd.new(File.read('spec/dtds/evernote-export3.dtd'))
12
+ doc = XML::Document.file(output_file)
13
+ expect(doc.validate(dtd)).to be true
14
+ end
15
+
16
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mg2en::Ingredient do
4
+
5
+ let(:parser) do
6
+ Mg2en::Parser.new(File.dirname(__FILE__) + '/fixtures/1.mgourmet3')
7
+ end
8
+
9
+ it 'parses ingredients' do
10
+ i = parser.recipes[0].ingredients
11
+ expect(i.size).to eql(2)
12
+ expect(i[0].measurement).to eql('clove')
13
+ expect(i[0].quantity).to eql('1')
14
+ expect(i[0].description).to eql('Garlic')
15
+ expect(i[0].direction).to eql('')
16
+ expect(i[1].direction).to eql('chopped & chopped')
17
+ expect(i[0].group?).to be false
18
+ end
19
+
20
+ it 'parses ingredient groups' do
21
+ i = parser.recipes[1].ingredients
22
+ expect(i.size).to eql(5)
23
+ expect(i[0].group?).to be false
24
+ ig = i[2]
25
+ expect(ig.group?).to be true
26
+ expect(ig.description).to eql('Group 1')
27
+ expect(ig.ingredients.size).to eql(2)
28
+ expect(ig.ingredients[0].description).to eql('saffron')
29
+ expect(ig.ingredients[1].description).to eql('salt')
30
+ end
31
+
32
+ it 'outputs ingredient' do
33
+ i = parser.recipes[0].ingredients
34
+ expect(i[1].to_s).to eql('1 pound Chicken, chopped & chopped')
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mg2en, 'parser' do
4
+
5
+ context 'with invalid input' do
6
+ it 'should error on non-existing file' do
7
+ expect do
8
+ Mg2en::Parser.new(File.dirname(__FILE__) +
9
+ '/fixtures/missing.mgourmet3')
10
+ end.to raise_error(ArgumentError)
11
+ end
12
+
13
+ it 'should error on malformed input' do
14
+ expect do
15
+ Mg2en::Parser.new('<plist version="1.0"><foo/></plist>')
16
+ end.to raise_error(RuntimeError)
17
+ end
18
+ end
19
+
20
+ context 'with valid input' do
21
+ let(:parser) do
22
+ Mg2en::Parser.new(File.dirname(__FILE__) + '/fixtures/1.mgourmet3')
23
+ end
24
+
25
+ it 'has corrent number of recipes' do
26
+ expect(parser.recipes.size).to eq(2)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mg2en::Recipe do
4
+
5
+ let(:parser) do
6
+ Mg2en::Parser.new(File.dirname(__FILE__) + '/fixtures/1.mgourmet3')
7
+ end
8
+
9
+ let(:bad_url_parser) do
10
+ Mg2en::Parser.new(File.dirname(__FILE__) + '/fixtures/2.mgourmet3')
11
+ end
12
+
13
+ it 'parses recipe' do
14
+ r = parser.recipes[1]
15
+ expect(r.name).to eql('Recipe B')
16
+ expect(r.summary).to eql('This is the introduction/summary.')
17
+ expect(r.note).to eql('These are the notes.')
18
+ expect(r.source).to eql('Test Fixture B')
19
+ expect(r.url).to eql('http://example.com/B')
20
+ end
21
+
22
+ it 'parses notes' do
23
+ n = parser.recipes[1].notes
24
+ expect(n[1]).to eql('This is a chef note.')
25
+ end
26
+
27
+ it "parses cuisines" do
28
+ c = parser.recipes[1].cuisine
29
+ expect(c).to eql(['North American', 'United States', 'Southern', 'Cajun'])
30
+ end
31
+
32
+ it 'ignores bad source URL' do
33
+ expect(bad_url_parser.recipes[0].url).to be nil
34
+ end
35
+
36
+ it 'returns empty string for empty source' do
37
+ expect(bad_url_parser.recipes[0].source).to be_empty
38
+ end
39
+
40
+ context 'when validating templates' do
41
+ dtd = XML::Dtd.new(File.read('spec/dtds/enml2.dtd'))
42
+ ['default'].each do |template|
43
+ it "#{template} template passes" do
44
+ Mg2en::Options.defaults[:template] = template
45
+ parser.recipes.each do |recipe|
46
+ doc = XML::Document.string(recipe.enml)
47
+ expect(doc.validate(dtd)).to be true
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,35 @@
1
+ require 'pathname'
2
+ require 'builder'
3
+ require 'mg2en'
4
+ require 'libxml'
5
+ include LibXML
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
12
+
13
+ # configure libxml-ruby
14
+ XML.default_load_external_dtd = true
15
+
16
+ # create a XML catalog for libxml to prevent hitting the network for external
17
+ # entity resolution
18
+ ENV['XML_CATALOG_FILES'] ||= File.expand_path('../../tmp/catalog.xml',
19
+ __FILE__)
20
+ dtds = File.expand_path('../dtds/', __FILE__)
21
+ catalog_dir = Pathname.new(ENV['XML_CATALOG_FILES']).dirname
22
+ Dir.mkdir(catalog_dir) unless Dir.exists?(catalog_dir)
23
+
24
+ unless File.exists?(ENV['XML_CATALOG_FILES'])
25
+ File.open(ENV['XML_CATALOG_FILES'], 'w') do |f|
26
+ # rubocop:disable LineLength
27
+ f << '<?xml version="1.0"?>'
28
+ f << '<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"'
29
+ f << ' "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">'
30
+ f << '<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">'
31
+ f << "<rewriteSystem systemIdStartString=\"http://www.w3.org/TR/xhtml1/DTD/\" rewritePrefix=\"file://#{dtds}/\"/>"
32
+ f << '</catalog>'
33
+ # rubocop:enable LineLength
34
+ end
35
+ end
@@ -0,0 +1,65 @@
1
+ !!! XML
2
+ <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
3
+ - base_font = "font-family:Verdana;font-size:12px;"
4
+ - heading_font = "font-family:Georgia,Times;"
5
+ - title_style = heading_font
6
+ - section_style = "#{heading_font};text-transform: uppercase;font-size:14px;"
7
+ - ingredient_group_style = "font-weight:bold;padding-left:10px;"
8
+ - quantity_style = "#{base_font}font-weight:bold;" +
9
+ - "text-align:right;vertical-align:top;padding-right:1em;" +
10
+ - "padding-left:1em;white-space:nowrap;"
11
+ - ingredient_style = base_font
12
+ - footer_style = "margin:4px;"
13
+ %en-note{style: base_font}
14
+ %h1{style: title_style}&= @name
15
+ %p&= @summary
16
+ %div
17
+ - if @image
18
+ %div{style: "float:right;padding-right:2em;"}
19
+ %en-media{type: "image/jpeg", hash: Digest::MD5.hexdigest(@image)}/
20
+ %h3{style: section_style} Ingredients
21
+ %table{style: "margin-left:10px;"}
22
+ - @ingredients.each do |i|
23
+ - if i.group?
24
+ %tr
25
+ %td{colspan: 2, style: ingredient_group_style}&= i
26
+ - i.ingredients.each do |ii|
27
+ %tr
28
+ %td{style: quantity_style}&= ii.quantity
29
+ %td{style: ingredient_style}
30
+ &= ii.without_quantity
31
+ = "FIXLINK" if ii.link?
32
+ - else
33
+ %tr
34
+ %td{style: quantity_style}&= i.quantity
35
+ %td{style: ingredient_style}
36
+ &= i.without_quantity
37
+ = "FIXLINK" if i.link?
38
+ %div{style: "clear:both;"}
39
+ %h3{style: section_style} Directions
40
+ %ol
41
+ - @directions.each do |d|
42
+ %li
43
+ - if d.label.present?
44
+ %span{style: "font-weight:bold;"}&= d.label + ": "
45
+ &= d.description
46
+ - if @notes.present?
47
+ %h3{style: section_style} Notes
48
+ %ul
49
+ - @notes.each do |n|
50
+ %li&= n
51
+ %hr/
52
+ - if @source.present?
53
+ %p{style: footer_style}
54
+ Source:
55
+ - if @url.present?
56
+ %a{href: @url}&= @source
57
+ - else
58
+ &= @source
59
+ %p{style: footer_style}
60
+ Yield:
61
+ - if @yield.present?
62
+ &= @yield
63
+ &= " / " if @servings > 0
64
+ - if @servings > 0
65
+ &= "#{@servings} servings"
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mg2en
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Hutchison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: plist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: builder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: haml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: image_science
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ruby_gntp
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: libxml-ruby
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: ''
168
+ email:
169
+ - jeff@jeffhutchison.com
170
+ executables:
171
+ - mg2en
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - Gemfile
177
+ - Guardfile
178
+ - LICENSE
179
+ - README.md
180
+ - Rakefile
181
+ - bin/mg2en
182
+ - lib/mg2en.rb
183
+ - lib/mg2en/direction.rb
184
+ - lib/mg2en/generator.rb
185
+ - lib/mg2en/ingredient.rb
186
+ - lib/mg2en/options.rb
187
+ - lib/mg2en/parser.rb
188
+ - lib/mg2en/recipe.rb
189
+ - lib/mg2en/version.rb
190
+ - mg2en.gemspec
191
+ - spec/direction_spec.rb
192
+ - spec/dtds/enml2.dtd
193
+ - spec/dtds/evernote-export3.dtd
194
+ - spec/dtds/xhtml-lat1.ent
195
+ - spec/dtds/xhtml-special.ent
196
+ - spec/dtds/xhtml-symbol.ent
197
+ - spec/fixtures/1.mgourmet3
198
+ - spec/fixtures/2.mgourmet3
199
+ - spec/generator_spec.rb
200
+ - spec/ingredient_spec.rb
201
+ - spec/parser_spec.rb
202
+ - spec/recipe_spec.rb
203
+ - spec/spec_helper.rb
204
+ - templates/default.haml
205
+ homepage: https://github.com/jhh/mg2en
206
+ licenses:
207
+ - MIT
208
+ metadata: {}
209
+ post_install_message:
210
+ rdoc_options: []
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ requirements: []
224
+ rubyforge_project:
225
+ rubygems_version: 2.2.0
226
+ signing_key:
227
+ specification_version: 4
228
+ summary: Convert MacGourmet plist export format to Evernote import format
229
+ test_files:
230
+ - spec/direction_spec.rb
231
+ - spec/dtds/enml2.dtd
232
+ - spec/dtds/evernote-export3.dtd
233
+ - spec/dtds/xhtml-lat1.ent
234
+ - spec/dtds/xhtml-special.ent
235
+ - spec/dtds/xhtml-symbol.ent
236
+ - spec/fixtures/1.mgourmet3
237
+ - spec/fixtures/2.mgourmet3
238
+ - spec/generator_spec.rb
239
+ - spec/ingredient_spec.rb
240
+ - spec/parser_spec.rb
241
+ - spec/recipe_spec.rb
242
+ - spec/spec_helper.rb
243
+ has_rdoc: