nsf 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,17 +13,6 @@ ARGV.each do |filename|
13
13
  doc = Nsf::Document.from_nsf(content)
14
14
 
15
15
  File.open("#{filename}.html", "w") do |f|
16
- f << <<-EOF
17
- <!doctype html>
18
- <html>
19
- <head>
20
- <meta charset="utf-8">
21
- <title>#{doc.title}</title>
22
- </head>
23
- <body>
24
- #{doc.to_html}
25
- </body>
26
- </html>
27
- EOF
16
+ f << doc.to_html
28
17
  end
29
18
  end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "nsf"
4
+
5
+ ARGV.each do |filename|
6
+ if !File.exist?(filename)
7
+ puts "Could not find #{filename}, skipping"
8
+ next
9
+ end
10
+
11
+ content = File.read(filename)
12
+
13
+ doc = Nsf::Document.from_nsf(content)
14
+
15
+ File.open("#{filename}.pdf", "w") do |f|
16
+ f << doc.to_pdf
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "nsf"
4
+
5
+ ARGV.each do |filename|
6
+ if !File.exist?(filename)
7
+ puts "Could not find #{filename}, skipping"
8
+ next
9
+ end
10
+
11
+ content = File.read(filename)
12
+
13
+ doc = Nsf::Document.from_text(content)
14
+
15
+ File.open("#{filename}.html", "w") do |f|
16
+ f << <<-EOF
17
+ <!doctype html>
18
+ <html>
19
+ <head>
20
+ <meta charset="utf-8">
21
+ <title>#{doc.title}</title>
22
+ </head>
23
+ <body>
24
+ #{doc.to_html}
25
+ </body>
26
+ </html>
27
+ EOF
28
+ end
29
+ end
@@ -17,7 +17,7 @@ module Nsf
17
17
  BLOCK_INITIATING_TAGS = %w(article aside body blockquote dd dt header li nav p pre section td th ul)
18
18
 
19
19
  BLOCK_PLAIN_TEXT_TAGS = %w(pre plaintext listing xmp)
20
-
20
+
21
21
  ENHANCERS = { %w(b strong) => "*", %(i em) => "_" }
22
22
 
23
23
  def self.from_html(text)
@@ -56,7 +56,7 @@ module Nsf
56
56
  paragraph_text = current_text.gsub(/[[:space:]]+/, ' ').strip
57
57
  blocks << Paragraph.new(paragraph_text) if paragraph_text.present?
58
58
  current_text.replace("")
59
-
59
+
60
60
 
61
61
  # if BLOCK_PLAIN_TEXT_TAGS.include?(node_name)
62
62
  # blocks.concat(Nsf::Document.from_text(current_text).nodes)
@@ -65,7 +65,7 @@ module Nsf
65
65
 
66
66
  return
67
67
  end
68
-
68
+
69
69
  if ENHANCERS.keys.flatten.include?(node_name)
70
70
  ENHANCERS.each_pair do |tags, nsf_rep|
71
71
  if tags.include?(node_name)
@@ -76,7 +76,7 @@ module Nsf
76
76
  end
77
77
  return
78
78
  end
79
-
79
+
80
80
  #Pretend that the children of this node were siblings of this node (move them one level up the tree)
81
81
  if (TEXT_TAGS + BLOCK_PASSTHROUGH_TAGS).include?(node_name)
82
82
  node.children.each { |n| iterate.call(n, blocks, current_text) }
@@ -110,10 +110,21 @@ module Nsf
110
110
  end
111
111
 
112
112
  def to_html
113
- nodes.map(&:to_html).join
113
+ <<-EOF
114
+ <!doctype html>
115
+ <html>
116
+ <head>
117
+ <meta charset="utf-8">
118
+ <title>#{title}</title>
119
+ </head>
120
+ <body>
121
+ #{nodes.map(&:to_html).join}
122
+ </body>
123
+ </html>
124
+ EOF
114
125
  end
115
126
  end
116
-
127
+
117
128
  class Paragraph
118
129
  def to_html_fragment(escape = true)
119
130
  out = (escape ? CGI.escapeHTML(@text) : @text).split(BOLD_ITALIC_REGEX)
@@ -122,7 +133,7 @@ module Nsf
122
133
  in_bold = false
123
134
  in_italic = false
124
135
 
125
- out.map! do |element|
136
+ out.map! do |element|
126
137
  if element == "*"
127
138
  in_bold = !in_bold
128
139
  in_bold ? "<b>" : "</b>" #Note that in_bold has been inverted, so this is inverted as well
@@ -1,3 +1,3 @@
1
1
  module Nsf
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-16 00:00:00.000000000 Z
12
+ date: 2014-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -97,6 +97,8 @@ email:
97
97
  - i@bloople.net
98
98
  executables:
99
99
  - nsf2html
100
+ - nsf2pdf
101
+ - txt2html
100
102
  extensions: []
101
103
  extra_rdoc_files: []
102
104
  files:
@@ -105,6 +107,8 @@ files:
105
107
  - Gemfile.lock
106
108
  - Rakefile
107
109
  - bin/nsf2html
110
+ - bin/nsf2pdf
111
+ - bin/txt2html
108
112
  - lib/nsf.rb
109
113
  - lib/nsf/formats/fonts/Apache License Version 2.txt
110
114
  - lib/nsf/formats/fonts/OpenSans-Bold.ttf