livetext 0.5.2 → 0.5.3

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/bin/livetext +20 -0
  3. data/lib/bookish.rb +212 -0
  4. data/lib/calibre.rb +24 -0
  5. data/lib/liveblog.rb +195 -0
  6. data/lib/livemagick.rb +131 -0
  7. data/lib/livetext.rb +605 -0
  8. data/lib/markdown.rb +30 -0
  9. data/lib/pyggish.rb +194 -0
  10. data/lib/tutorial.rb +89 -0
  11. data/livetext-0.5.2.gem +0 -0
  12. data/livetext.gemspec +99 -4
  13. data/test/cleanup +1 -0
  14. data/test/newtest +10 -0
  15. data/test/rawtext.inc +4 -0
  16. data/test/simple_mixin.rb +3 -0
  17. data/test/simplefile.inc +2 -0
  18. data/test/test.rb +77 -0
  19. data/test/testfiles/basic_formatting/expected-error.txt +0 -0
  20. data/test/testfiles/basic_formatting/expected-output.txt +10 -0
  21. data/test/testfiles/basic_formatting/source.ltx +8 -0
  22. data/test/testfiles/block_comment/expected-error.txt +0 -0
  23. data/test/testfiles/block_comment/expected-output.txt +5 -0
  24. data/test/testfiles/block_comment/source.ltx +19 -0
  25. data/test/testfiles/comments_ignored_1/expected-error.txt +0 -0
  26. data/test/testfiles/comments_ignored_1/expected-output.txt +4 -0
  27. data/test/testfiles/comments_ignored_1/source.ltx +7 -0
  28. data/test/testfiles/copy_is_raw/expected-error.txt +0 -0
  29. data/test/testfiles/copy_is_raw/expected-output.txt +7 -0
  30. data/test/testfiles/copy_is_raw/source.ltx +4 -0
  31. data/test/testfiles/def_method/expected-error.txt +2 -0
  32. data/test/testfiles/def_method/expected-output.txt +5 -0
  33. data/test/testfiles/def_method/source.ltx +10 -0
  34. data/test/testfiles/example_alpha/expected-error.txt +0 -0
  35. data/test/testfiles/example_alpha/expected-output.txt +23 -0
  36. data/test/testfiles/example_alpha/source.ltx +17 -0
  37. data/test/testfiles/example_alpha2/expected-error.txt +0 -0
  38. data/test/testfiles/example_alpha2/expected-output.txt +12 -0
  39. data/test/testfiles/example_alpha2/source.ltx +24 -0
  40. data/test/testfiles/fixit +6 -0
  41. data/test/testfiles/functions/expected-error.txt +0 -0
  42. data/test/testfiles/functions/expected-output.txt +8 -0
  43. data/test/testfiles/functions/source.ltx +11 -0
  44. data/test/testfiles/hello_world/expected-error.txt +0 -0
  45. data/test/testfiles/hello_world/expected-output.txt +2 -0
  46. data/test/testfiles/hello_world/source.ltx +2 -0
  47. data/test/testfiles/more_complex_vars/expected-error.txt +0 -0
  48. data/test/testfiles/more_complex_vars/expected-output.txt +4 -0
  49. data/test/testfiles/more_complex_vars/source.ltx +5 -0
  50. data/test/testfiles/raw_text_block/expected-error.txt +0 -0
  51. data/test/testfiles/raw_text_block/expected-output.txt +14 -0
  52. data/test/testfiles/raw_text_block/source.ltx +16 -0
  53. data/test/testfiles/sigil_can_change/expected-error.txt +0 -0
  54. data/test/testfiles/sigil_can_change/expected-output.txt +6 -0
  55. data/test/testfiles/sigil_can_change/source.ltx +11 -0
  56. data/test/testfiles/simple_copy/expected-error.txt +0 -0
  57. data/test/testfiles/simple_copy/expected-output.txt +7 -0
  58. data/test/testfiles/simple_copy/source.ltx +6 -0
  59. data/test/testfiles/simple_include/expected-error.txt +0 -0
  60. data/test/testfiles/simple_include/expected-output.txt +7 -0
  61. data/test/testfiles/simple_include/source.ltx +6 -0
  62. data/test/testfiles/simple_mixin/expected-error.txt +0 -0
  63. data/test/testfiles/simple_mixin/expected-output.txt +5 -0
  64. data/test/testfiles/simple_mixin/source.ltx +6 -0
  65. data/test/testfiles/simple_vars/expected-error.txt +0 -0
  66. data/test/testfiles/simple_vars/expected-output.txt +6 -0
  67. data/test/testfiles/simple_vars/source.ltx +7 -0
  68. data/test/testfiles/single_raw_line/expected-error.txt +0 -0
  69. data/test/testfiles/single_raw_line/expected-output.txt +10 -0
  70. data/test/testfiles/single_raw_line/source.ltx +8 -0
  71. metadata +76 -9
  72. data/dlt +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10e2a4593cf80b8c04fdcb0f4b3d7b4b200f7d8c
4
- data.tar.gz: 1e06304ea3cf2ddee375222f4b84bc936b3310c9
3
+ metadata.gz: 6e687858325843870a52b6326917c6fd29064dd8
4
+ data.tar.gz: ab6d2aedac807c98a661267f3143037f7404be69
5
5
  SHA512:
6
- metadata.gz: 47ae7c83b121dcbf74b40481817cb138b09750dc73af35a03e9c9c0534f1468da33805882f11458a80774ff2efeffed847b481fce18efab9a6bc118c55e3dc31
7
- data.tar.gz: 037f47fc8651104d6a2aa731d1dccbc9ee3bfac625cf144a57b7963b1cf24f090b61a02efae4511f79a0e3e3219d6090b23339eb4bfc3c91a410bc1a8e3db915
6
+ metadata.gz: 00972e0a5a2256bbac5a88aad28dd0feb601c14907b8c8daac46bb7dbf162842b0447f65db2f755f52296f168d078aa9ee298ca867b9c0feacbe3832ed7941c2
7
+ data.tar.gz: a597ae81fa81400a6c15571de5fad559e4c748d7113d19899aa415909ad2ac87c748bfd92b1d6e23fba39f4e27515211447a9495fb097d02692ab489b741fc23
data/bin/livetext ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/livetext'
4
+
5
+ def handle_ltx(src)
6
+ abort "Unknown file extension" unless src =~ /.ltx$/
7
+
8
+ Livetext.handle_file(src)
9
+ end
10
+
11
+ # Main
12
+
13
+ if ARGV.first == "--clean-all"
14
+ clean_all
15
+ exit
16
+ end
17
+
18
+ src = ARGV.first
19
+ handle_ltx(src)
20
+
data/lib/bookish.rb ADDED
@@ -0,0 +1,212 @@
1
+ # noinspection RubyQuotedStringsInspection
2
+ def hardbreaks
3
+ @hard = false
4
+ @hard = true unless @_args.first == "off"
5
+ end
6
+
7
+ def hardbreaks?
8
+ @hard
9
+ end
10
+
11
+ def credit
12
+ # really just a place marker in source
13
+ end
14
+
15
+ def list
16
+ _puts "<ul>"
17
+ _body {|line| _puts "<li>#{line}</li>" }
18
+ _puts "</ul>"
19
+ end
20
+
21
+ def list!
22
+ _puts "<ul>"
23
+ lines = _body.each # {|line| _puts "<li>#{line}</li>" }
24
+ loop do
25
+ line = lines.next
26
+ line = _formatting(line)
27
+ if line[0] == " "
28
+ _puts line
29
+ else
30
+ _puts "<li>#{line}</li>"
31
+ end
32
+ end
33
+ _puts "</ul>"
34
+ end
35
+
36
+ def alpha_columns
37
+ n = @_args.first.to_i # FIXME: what if missing?
38
+ words = []
39
+ _body do |line|
40
+ words << line.chomp
41
+ end
42
+ words.sort!
43
+ _puts "<table cellpadding=10>"
44
+ words.each_slice(n) do |w|
45
+ items = w.map {|x| "<tt>#{x}</tt>" }
46
+ _puts "<tr><td width=5%></td><td>" + items.join("</td><td>") + "</td></tr>"
47
+ end
48
+ _puts "</table>"
49
+ end
50
+
51
+ def comment
52
+ _body { } # ignore body
53
+ end
54
+
55
+ def _errout(*args)
56
+ ::STDERR.puts *args
57
+ end
58
+
59
+ def _nbsp(n)
60
+ "&nbsp;"*n
61
+ end
62
+
63
+ def _slug(str)
64
+ s2 = str.chomp.strip.gsub(/[?:,()'"\/]/,"").gsub(/ /, "-").downcase
65
+ # _errout "SLUG: #{str} => #{s2}"
66
+ s2
67
+ end
68
+
69
+ def image
70
+ name = @_args[0]
71
+ _puts "<img src='#{name}'></img>"
72
+ end
73
+
74
+ def figure
75
+ name = @_args[0]
76
+ num = @_args[1]
77
+ title = @_args[2..-1].join(" ")
78
+ title = _formatting(title)
79
+ _puts "<img src='#{name}'></img>"
80
+ _puts "<center><b>Figure #{num}</b> #{title}</center>"
81
+ end
82
+
83
+ def chapter
84
+ # _errout("chapter")
85
+ @chapter = @_args.first.to_i
86
+ @sec = @sec2 = 0
87
+ title = @_data.split(" ",2)[1]
88
+ @toc << "<br><b>#@chapter</b> #{title}<br>"
89
+ _next_output(_slug(title))
90
+ _puts "<title>#{@chapter}. #{title}</title>"
91
+ _puts <<-HTML
92
+ <h2>Chapter #{@chapter}</h1>
93
+ <h1>#{title}</h1>
94
+
95
+ HTML
96
+ end
97
+
98
+ def chapterN
99
+ @chapter += 1
100
+ @sec = @sec2 = 0
101
+ title = @_data # .split(" ",2)[1]
102
+ _errout("Chapter #@chapter: #{title}")
103
+ @toc << "<br><b>#@chapter</b> #{title}<br>"
104
+ _next_output(_slug(title))
105
+ _puts "<title>#{@chapter}. #{title}</title>"
106
+ _puts <<-HTML
107
+ <h2>Chapter #{@chapter}</h1>
108
+ <h1>#{title}</h1>
109
+
110
+ HTML
111
+ end
112
+
113
+ def sec
114
+ @sec += 1
115
+ @sec2 = 0
116
+ @section = "#@chapter.#@sec"
117
+ # _errout("section #@section")
118
+ @toc << "#{_nbsp(3)}<b>#@section</b> #@_data<br>"
119
+ _next_output(_slug(@_data))
120
+ _puts "<h3>#@section #{@_data}</h3>\n"
121
+ end
122
+
123
+ def subsec
124
+ @sec2 += 1
125
+ @subsec = "#@chapter.#@sec.#@sec2"
126
+ @toc << "#{_nbsp(6)}<b>#@subsec</b> #@_data<br>"
127
+ # _errout("section #@subsec")
128
+ _next_output(_slug(@_data))
129
+ _puts "<h3>#@subsec #{@_data}</h3>\n"
130
+ end
131
+
132
+ def table
133
+ @table_num ||= 0
134
+ @table_num += 1
135
+ title = @_data
136
+ delim = " :: "
137
+ _puts "<br><center><table border=1 width=90% cellpadding=5>"
138
+ lines = _body
139
+ maxw = nil
140
+ lines.each do |line|
141
+ _formatting(line)
142
+ cells = line.split(delim)
143
+ wide = cells.map {|x| x.length }
144
+ maxw = [0] * cells.size
145
+ maxw = maxw.map.with_index {|x, i| [x, wide[i]].max }
146
+ end
147
+
148
+ sum = maxw.inject(0, :+)
149
+ maxw.map! {|x| (x/sum*100).floor }
150
+
151
+ lines.each do |line|
152
+ cells = line.split(delim)
153
+ _puts "<tr>"
154
+ cells.each.with_index {|cell, i| ; _puts " <td width=#{maxw}%>#{cell}</td>" }
155
+ _puts "</tr>"
156
+ end
157
+ _puts "</table>"
158
+ @toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
159
+ _next_output(_slug("table_#{title}"))
160
+ _puts "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
161
+ end
162
+
163
+ def toc!
164
+ _debug "Closing TOC"
165
+ @toc.close
166
+ rescue => err
167
+ _errout "Exception: #{err.inspect}"
168
+ end
169
+
170
+ def toc2
171
+ file = @_args[0]
172
+ @toc.close
173
+ ::File.write(file, <<-EOS)
174
+ <p style="page-break-after:always;"></p>
175
+ <meta charset='UTF-8'>
176
+
177
+ <center><h2>Fake (non-hyperlinked) Table of Contents</h2></center>
178
+
179
+ EOS
180
+ system("cat toc.tmp >>#{file}")
181
+ end
182
+
183
+ def missing
184
+ @toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
185
+ _print "<br><font color=red><i>[Material missing"
186
+ _print ": #@_data" unless @_data.empty?
187
+ _puts "]</i></font><br>\n "
188
+ end
189
+
190
+ def TBC
191
+ @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
192
+ _print "<br><font color=red><i>To be continued...</i></font><br>"
193
+ end
194
+
195
+ def note
196
+ _puts "<br><font color=red><i>Note: "
197
+ _puts @_data
198
+ _puts "</i></font><br>\n "
199
+ end
200
+
201
+ def quote
202
+ _puts "<blockquote>"
203
+ _puts _body
204
+ _puts "</blockquote>"
205
+ end
206
+
207
+ def init_bookish
208
+ @toc_file = "toc.tmp"
209
+ @toc = ::File.new(@toc_file, "w")
210
+ @chapter = -1
211
+ end
212
+
data/lib/calibre.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ def epub!
4
+ out = _var_substitution(@_args[0])
5
+ src = @_args[1]
6
+ @cover = @_args[2]
7
+ if ::File.directory?(src)
8
+ files = ::Dir["#{src}/*"].grep /\.html$/
9
+ cmd = "cat #{files.join(' ')} >TEMP.html"
10
+ system(cmd)
11
+ else
12
+ raise "Not supported yet"
13
+ end
14
+
15
+ cmd = "ebook-convert "
16
+ cmd << "TEMP.html #{out}.epub "
17
+ cmd << "--cover #@cover " if @cover
18
+ system(cmd)
19
+
20
+ str = `links -dump TEMP.html | wc -w`
21
+ nw = str.split[0]
22
+ puts "Approx words: #{nw}"
23
+ ::FileUtils.rm("TEMP.html")
24
+ end
data/lib/liveblog.rb ADDED
@@ -0,0 +1,195 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ def init_liveblog
5
+ @teaser = ""
6
+ @body = ""
7
+ @dest = @teaser
8
+ @meta = ::OpenStruct.new
9
+ # @views = ::Dir.entries("#{@config.root}/views") - %w[. ..]
10
+ @deployment = {}
11
+ # @views.each do |per|
12
+ # file = ""#{@config.root}views/#{per}/deploy"
13
+ # server, destdir = ::File.readlines(file).map {|x| x.chomp }
14
+ # @deployment[per] = [server, destdir]
15
+ # end
16
+ end
17
+
18
+ def _errout(*args)
19
+ ::STDERR.puts *args
20
+ end
21
+
22
+ def _passthru(line)
23
+ OLD_formatting(line)
24
+ _var_substitution(line)
25
+ @dest << line
26
+ end
27
+
28
+ def title
29
+ @meta.title = _data
30
+ end
31
+
32
+ def pubdate
33
+ _debug "data = #@_data"
34
+ match = /(\d{4}).(\d{2}).(\d{2})/.match _data
35
+ junk, y, m, d = match.to_a
36
+ y, m, d = y.to_i, m.to_i, d.to_i
37
+ @meta.date = ::Date.new(y, m, d)
38
+ @meta.pubdate = "%04d%02d%02d" % [y, m, d]
39
+ end
40
+
41
+ def categories
42
+ _debug "args = #{_args}"
43
+ @meta.categories = _args
44
+ end
45
+
46
+ def views
47
+ _debug "data = #{_args}"
48
+ @meta.views = _args # + ["main"]
49
+ end
50
+
51
+ def readmore
52
+ @meta.teaser = @dest
53
+ @dest = @dest + @body
54
+ end
55
+
56
+ def liveblog_version
57
+ end
58
+
59
+ def _slug(str)
60
+ date = @meta.pubdate
61
+ s2 = date + "-" + str.chomp.strip.gsub(/[?:,\.()'"\/]/,"").gsub(/ /, "-").downcase
62
+ # _errout "SLUG: #{str} => #{s2}"
63
+ s2
64
+ end
65
+
66
+ def finalize
67
+ @meta.slug = _slug(@meta.title)
68
+ @meta.body = @dest
69
+ # @list = {} # FIXME Make hash by view
70
+ # @meta.views.each {|per| generate(per) }
71
+ # deploy
72
+ p @meta
73
+ @meta
74
+ end
75
+
76
+ #####
77
+
78
+ def generate(view)
79
+ dir = "views/#{view}"
80
+ _errout("dir = #{dir}")
81
+ out = "#{dir}/compiled/#{@meta.slug}.html"
82
+ @post_header = ::File.read("#{dir}/post_header.html")
83
+ @post_trailer = ::File.read("#{dir}/post_trailer.html")
84
+ @template = ::File.read("#{dir}/template.html")
85
+
86
+ title = @meta.title
87
+ title.gsub!("'",'&#39;')
88
+ title.gsub!('"','_')
89
+ teaser = @meta.teaser
90
+ server, dir = @deployment[view]
91
+ url = "http://#{server}/#{server}/#{@meta.slug}.html"
92
+ tweet = "&#34;#{title}&#34;\n"
93
+ tweet.gsub!("'",'&#39;')
94
+
95
+ text = eval("<<HEREDOC\n#@template\nHEREDOC")
96
+ _errout "Writing #{text.size} bytes to #{out}"
97
+ ::File.write(out, text)
98
+
99
+ metaname = out.sub(/html/, "yaml")
100
+ _errout "Writing #{@meta.to_yaml.size} bytes to #{metaname}"
101
+ ::File.write(metaname, @meta.to_yaml)
102
+ @list[view] ||= []
103
+ @list[view] << out << metaname
104
+ generate_index(view)
105
+ rescue => err
106
+ ::STDERR.puts "#{err}\n#{err.backtrace.map {|x| " " + x }.join("\n") }"
107
+ end
108
+
109
+ def generate_index(view) # FIXME
110
+ dir = "views/#{view}"
111
+ cdir = "views/#{view}/compiled"
112
+ posts = ::Dir["#{cdir}/*.yaml"].sort {|a,b| b <=> a }
113
+ out = ::File.read("#{dir}/blogheader.html")
114
+
115
+ server, destdir = @deployment[view]
116
+
117
+ posts.each do |fname|
118
+ meta = ::YAML.load(::File.read(fname))
119
+ # name2 = fname.sub("compiled",) # FIXME
120
+ name2 = fname.sub("compiled",destdir)
121
+ html = name2.sub(/yaml/, "html")
122
+ out << <<-HTML
123
+ <br>
124
+ <font size=+1>#{meta["pubdate"]}&nbsp;&nbsp;</font>
125
+ <font size=+2 color=blue><a href=../#{html} style="text-decoration: none">#{meta["title"]}</font></a>
126
+ <br>
127
+ #{meta["teaser"]}
128
+ <a href=../#{html} style="text-decoration: none">Read more...</a>
129
+ <br><br>
130
+ <hr>
131
+ HTML
132
+ end
133
+
134
+ out << <<-HTML
135
+ </body>
136
+ </html>
137
+ HTML
138
+ ::File.write("#{cdir}/index.html", out)
139
+ @list[view] << "#{cdir}/index.html"
140
+ _errout @list.inspect
141
+ end
142
+
143
+ def deploy # FIXME
144
+ if @list.empty?
145
+ puts "No changes to deploy."
146
+ return
147
+ end
148
+ puts "Want to deploy? (y/N):"
149
+ inp = ::File.open("/dev/tty")
150
+ resp = inp.gets.chomp
151
+ return unless resp == "y"
152
+
153
+ puts "Deploying:"
154
+ @list.each_pair do |per, files|
155
+ server, dir = @deployment[per]
156
+ cmd = "scp #{files.join(' ')} root@#{server}:#{dir}"
157
+ puts cmd
158
+ system cmd
159
+ end
160
+ end
161
+
162
+ def redeploy(per)
163
+ puts "Redeploying:"
164
+ server, dir = @deployment[per]
165
+ cmd = "scp #{files.join(' ')} root@#{server}:#{dir}"
166
+ puts cmd
167
+ # system cmd
168
+ end
169
+
170
+ ################ Logic...
171
+
172
+ =begin
173
+ New post:
174
+ specify file name
175
+ output metadata (yaml), html
176
+ output task list??
177
+ How handle views?
178
+ Generate indices
179
+ Deploy
180
+
181
+ Handling views:
182
+ Each view has its own index
183
+ Separate boilerplate (header/trailer)
184
+ Separate deployments (separate host info)
185
+ 'main' linked to default?
186
+ 'test' view
187
+ generate is now dependent on view
188
+
189
+ Under view dir:
190
+ header/trailer
191
+ index
192
+ host info? (only for deploy)
193
+ separate compiled/ directory??
194
+ =end
195
+