RubySocialClub 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -1
- data/Gemfile +1 -1
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/RubySocialClub.gemspec +16 -19
- data/bin/RubySocialClub +2 -3
- data/lib/RubySocialClub.rb +3 -4
- data/lib/RubySocialClub/convertor.rb +168 -0
- data/lib/RubySocialClub/irbtorb.rb +29 -0
- data/lib/RubySocialClub/rake_tasks.rb +108 -0
- data/lib/RubySocialClub/snippet.rb +89 -0
- data/lib/RubySocialClub/version.rb +1 -1
- data/spec/convertor_spec.rb +51 -0
- data/spec/files/rakefile.rb +8 -0
- data/spec/files/sources/object.rb +11 -0
- data/spec/rake_tasks_spec.rb +38 -0
- data/spec/spec_helper.rb +6 -0
- metadata +60 -11
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alessio Caiazza
|
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
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RubySocialClub
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'RubySocialClub'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install RubySocialClub
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/RubySocialClub.gemspec
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "RubySocialClub/version"
|
2
|
+
require File.expand_path('../lib/RubySocialClub/version', __FILE__)
|
4
3
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
s.summary = %q{Il verso della stringa - ahhhhhhhhhrhhhhhrhhh}
|
12
|
-
s.description = %q{Demo gems made during the first Ruby Social Club in Florence }
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alessio Caiazza"]
|
6
|
+
gem.email = ["nolith@abisso.org"]
|
7
|
+
gem.description = %q{A tool for writing beamer presentation containig ruby code examples}
|
8
|
+
gem.summary = %q{This tool allows you to include real ruby example, with output, in latex presentations.}
|
9
|
+
gem.homepage = ""
|
13
10
|
|
14
|
-
|
11
|
+
#gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "RubySocialClub"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RubySocialClub::VERSION
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
# specify any dependencies here; for example:
|
22
|
-
# s.add_development_dependency "rspec"
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
18
|
+
gem.add_dependency 'thor'
|
19
|
+
gem.add_dependency 'syntax'
|
20
|
+
gem.add_development_dependency 'rspec'
|
24
21
|
end
|
data/bin/RubySocialClub
CHANGED
data/lib/RubySocialClub.rb
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
#encoding: ISO-8859-15
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'syntax/convertors/html'
|
4
|
+
|
5
|
+
module RubySocialClub
|
6
|
+
|
7
|
+
# TODO: to refactor
|
8
|
+
class Convertor
|
9
|
+
include REXML
|
10
|
+
|
11
|
+
SEPARATOR = "\xa4".freeze
|
12
|
+
|
13
|
+
attr_accessor :source_file
|
14
|
+
|
15
|
+
def self.prepare_irb_session(file)
|
16
|
+
tmp = `cat #{file} | bundle exec irb -f --noreadline --prompt-mode xmp`
|
17
|
+
tmp.gsub!(/^\s*Switch to inspect mode\.\s*$/,'')
|
18
|
+
tmp.gsub!(/\s*#NO=OUTPUT.*?==>/m, "\n ==>")
|
19
|
+
tmp.gsub!(/\s*#NO=RESULT\n\s*==>\s*.*?\n/m, "\n")
|
20
|
+
tmp.gsub!(/\s*\n\s*==>\s*/m, "\t\"thisistheresult_bwdye\"\t")
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(src, parse_xmp = false)
|
24
|
+
@source_file=src
|
25
|
+
@parse_xmp = parse_xmp
|
26
|
+
clear
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear
|
30
|
+
@code_html = nil
|
31
|
+
@html_latex = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_html
|
35
|
+
return @code_html unless @code_html.nil?
|
36
|
+
|
37
|
+
code= File.read(@source_file, :encoding => 'ISO-8859-15')
|
38
|
+
|
39
|
+
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
|
40
|
+
@code_html = convertor.convert( code )
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_latex
|
44
|
+
return @html_latex unless @html_latex.nil?
|
45
|
+
|
46
|
+
text = to_html.encode('ISO-8859-15')
|
47
|
+
|
48
|
+
file = Document.new text
|
49
|
+
body = file.elements['//pre[1]']
|
50
|
+
|
51
|
+
first = true
|
52
|
+
|
53
|
+
r = ''
|
54
|
+
body.each do | e |
|
55
|
+
if e.is_a?Text
|
56
|
+
t = e.to_s
|
57
|
+
t = t[1..-1] if first
|
58
|
+
first = false
|
59
|
+
r << latexize(t)
|
60
|
+
else
|
61
|
+
first = false
|
62
|
+
text = e.get_text.to_s
|
63
|
+
r << text.split("\n",-1).map do | t |
|
64
|
+
if e.attributes['class'] == 'string'
|
65
|
+
codes = "\\codestring"
|
66
|
+
tmp = e.map do |ee|
|
67
|
+
if ee.is_a?Text
|
68
|
+
latexize(ee.to_s)
|
69
|
+
else
|
70
|
+
eet = ee.get_text.to_s
|
71
|
+
pref = remap(ee.attributes['class'])
|
72
|
+
"#{pref}#{'{' unless pref.nil?}#{latexize(eet)}#{'}' unless pref.nil?}"
|
73
|
+
end
|
74
|
+
end.join
|
75
|
+
codes + "{" + tmp + "}"
|
76
|
+
elsif (latexize(t) !~ /^\s*$/)
|
77
|
+
pref = remap(e.attributes['class'])
|
78
|
+
"#{pref}#{'{' if pref != ""}#{latexize(t)}#{'}' if pref != ""}"
|
79
|
+
else
|
80
|
+
''
|
81
|
+
end
|
82
|
+
end.join("\n")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
lines = r.split("\n")
|
87
|
+
lines.map! do | line |
|
88
|
+
tmp = line.gsub(/^\s*/) { | m | "\\RubyIndent{#{m.gsub(/\t/, ' ').length}}" }
|
89
|
+
SEPARATOR + tmp.force_encoding('ISO-8859-15') + SEPARATOR
|
90
|
+
end
|
91
|
+
@html_latex = lines.join("\n")
|
92
|
+
if @parse_xmp
|
93
|
+
result_to_latex
|
94
|
+
else
|
95
|
+
@html_latex
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def result_to_latex
|
101
|
+
@html_latex.gsub!(/\t"\\codestring\{thisistheresult\\_bwdye\}"\t(.*)#{Regexp.quote(SEPARATOR)}$/,
|
102
|
+
"\t\\XMPresult{\\1}#{SEPARATOR}")
|
103
|
+
@html_latex.gsub!(/\\codekeyword\{class\t\}"thisistheresult\\_bwdye"\t(.*)#{Regexp.quote(SEPARATOR)}$/,
|
104
|
+
"class\t\\XMPresult{\\1}#{SEPARATOR}")
|
105
|
+
@html_latex
|
106
|
+
end
|
107
|
+
protected :result_to_latex
|
108
|
+
|
109
|
+
def latexize(str)
|
110
|
+
str.gsub(%r!\\|\^|\$|<|>|&|"|#|\{|\}|"|~|_|%| |&!) do | match |
|
111
|
+
case match
|
112
|
+
when '\\' then '\ensuremath{\backslash}'
|
113
|
+
when '^' then '\ensuremath{\hat{\ }}'
|
114
|
+
when '$' then '\$'
|
115
|
+
when '<' then '<'
|
116
|
+
when '>' then '>'
|
117
|
+
when '&' then '\&'
|
118
|
+
when '"' then '"'
|
119
|
+
when '#' then '\#'
|
120
|
+
when '{' then '\{'
|
121
|
+
when '}' then '\}'
|
122
|
+
when '"' then '"'
|
123
|
+
when '~' then '\textasciitilde{}'
|
124
|
+
when '_' then '\_'
|
125
|
+
when '%' then '\%'
|
126
|
+
when ' ' then '\ '
|
127
|
+
when '&' then '\&'
|
128
|
+
end
|
129
|
+
end.gsub('<<', '<{}<').gsub('>>', '>{}>')
|
130
|
+
end
|
131
|
+
protected :latexize
|
132
|
+
|
133
|
+
def remap(string)
|
134
|
+
prefisso = "\\code"
|
135
|
+
suff = case string
|
136
|
+
when "comment"
|
137
|
+
"comment"
|
138
|
+
when "method"
|
139
|
+
"functionname"
|
140
|
+
when "attribute"
|
141
|
+
"variablename"
|
142
|
+
when "punct"
|
143
|
+
nil
|
144
|
+
when "constant"
|
145
|
+
"variablename"
|
146
|
+
when "number"
|
147
|
+
"type"
|
148
|
+
when "ident"
|
149
|
+
nil
|
150
|
+
when "symbol"
|
151
|
+
"type"
|
152
|
+
when "global"
|
153
|
+
"variablename"
|
154
|
+
when "string"
|
155
|
+
"string"
|
156
|
+
when "keyword"
|
157
|
+
"keyword"
|
158
|
+
else #esistono anche excape ed expr
|
159
|
+
nil
|
160
|
+
end
|
161
|
+
|
162
|
+
return prefisso + suff unless suff.nil?
|
163
|
+
return ""
|
164
|
+
end
|
165
|
+
protected :remap
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
irb = []
|
2
|
+
output = []
|
3
|
+
|
4
|
+
$stdin.read.split("\n").each do | line |
|
5
|
+
case line
|
6
|
+
when /^[>?]> (.*?)\s*$/
|
7
|
+
if output.length > 0
|
8
|
+
irb << [:output, output.join("\n")]
|
9
|
+
output = []
|
10
|
+
end
|
11
|
+
irb << [:input, $1]
|
12
|
+
when /^(.*?)=> (.*?)\s*$/
|
13
|
+
irb << [:result, "\t=result=>> #{$2}\n"]
|
14
|
+
o = $1
|
15
|
+
output << '#OUTPUT:' + o unless o =~ /^\S*$/
|
16
|
+
if output.length > 0
|
17
|
+
irb << [:output, output.join('')]
|
18
|
+
output = []
|
19
|
+
end
|
20
|
+
else
|
21
|
+
output << "#OUTPUT:#{line}\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
irb.each_index do | i |
|
26
|
+
irb[i][1] << "\n" if (irb[i][0] == :input) and (irb[i+1]) and (irb[i+1][0] != :result)
|
27
|
+
end
|
28
|
+
|
29
|
+
print irb.map{|type, text| text}.join("")
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
|
6
|
+
require 'RubySocialClub/convertor'
|
7
|
+
|
8
|
+
#CLEAN.include('*.o')
|
9
|
+
#CLOBBER.include('hello')
|
10
|
+
#
|
11
|
+
#task :default => ["hello"]
|
12
|
+
#
|
13
|
+
#SRC = FileList['*.c']
|
14
|
+
#OBJ = SRC.ext('o')
|
15
|
+
#
|
16
|
+
#rule '.o' => '.c' do |t|
|
17
|
+
# sh "cc -c -o #{t.name} #{t.source}"
|
18
|
+
#end
|
19
|
+
#
|
20
|
+
#file "hello" => OBJ do
|
21
|
+
# sh "cc -o hello #{OBJ}"
|
22
|
+
#end
|
23
|
+
#
|
24
|
+
## File dependencies go here ...
|
25
|
+
#file 'main.o' => ['main.c', 'greet.h']
|
26
|
+
#file 'greet.o' => ['greet.c']
|
27
|
+
|
28
|
+
def ruby_source(src)
|
29
|
+
|
30
|
+
files = generate_file_lists(src)
|
31
|
+
|
32
|
+
src_files = files[:src]
|
33
|
+
tex_files = files[:tex]
|
34
|
+
irb_tex_files = files[:irb]
|
35
|
+
output_files = files[:output]
|
36
|
+
|
37
|
+
desc "Generates all the source examples"
|
38
|
+
task :sources => tex_files
|
39
|
+
|
40
|
+
desc "Generates all the IRB source examples"
|
41
|
+
task :irb_sources => irb_tex_files
|
42
|
+
|
43
|
+
desc "Executes all the source examples"
|
44
|
+
task :output => output_files
|
45
|
+
|
46
|
+
desc "Generates snippets"
|
47
|
+
task :snippets do
|
48
|
+
snippet_src = RubySocialClub::Snippet.snippettize_dir(src)
|
49
|
+
puts "snippets in #{snippet_src}"
|
50
|
+
snippet_files = generate_file_lists(snippet_src)
|
51
|
+
|
52
|
+
task :snp_all => snippet_files[:tex]
|
53
|
+
task :snp_all => snippet_files[:irb]
|
54
|
+
task :snp_all => snippet_files[:output]
|
55
|
+
Rake::Task[:snp_all].invoke
|
56
|
+
end
|
57
|
+
CLEAN.include(File.join(src, 'snippets', '*.rb'))
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_file_lists(src)
|
61
|
+
src_files = FileList[File.join(src, '*.rb')]
|
62
|
+
tex_files = src_files.ext('tex')
|
63
|
+
irb_tex_files = src_files.ext('xmp.tex')
|
64
|
+
output_files = src_files.ext('out')
|
65
|
+
|
66
|
+
CLEAN.include(File.join(src, '*.tex'))
|
67
|
+
CLEAN.include(File.join(src, '*.xmp'))
|
68
|
+
CLEAN.include(File.join(src, '*.out'))
|
69
|
+
|
70
|
+
generate_task_basedfile_list(src_files, 'xmp') do |t, src|
|
71
|
+
tmp = RubySocialClub::Convertor.prepare_irb_session src
|
72
|
+
File.open(t.name, 'w:ISO-8859-15') { |f| f << tmp }
|
73
|
+
end
|
74
|
+
|
75
|
+
generate_task_basedfile_list(src_files, 'out') do |t, src|
|
76
|
+
sh "bundle exec ruby #{src} > #{t.name} 2>&1 ; true"
|
77
|
+
end
|
78
|
+
|
79
|
+
generate_task_basedfile_list(src_files, 'tex') do |t, src|
|
80
|
+
puts "#{src} -> #{t.name}"
|
81
|
+
c = RubySocialClub::Convertor.new(src)
|
82
|
+
latex = c.to_latex
|
83
|
+
File.open(t.name, 'w:ISO-8859-15') { |f| f << latex }
|
84
|
+
end
|
85
|
+
|
86
|
+
generate_task_basedfile_list(src_files.ext('xmp'), 'xmp.tex') do |t, src|
|
87
|
+
puts "#{src} -> #{t.name}"
|
88
|
+
c = RubySocialClub::Convertor.new(src, true)
|
89
|
+
latex = c.to_latex
|
90
|
+
File.open(t.name, 'w:ISO-8859-15') { |f| f << latex }
|
91
|
+
end
|
92
|
+
|
93
|
+
{ :src => src_files, :tex => tex_files,
|
94
|
+
:irb => irb_tex_files, :output => output_files }
|
95
|
+
end
|
96
|
+
|
97
|
+
def generate_task_basedfile_list(file_list, new_ext)
|
98
|
+
file_list.each do |src_file|
|
99
|
+
dst_file = src_file.clone
|
100
|
+
src_ext_len = File.extname(src_file).length() -1
|
101
|
+
dst_file[-src_ext_len..-1] = new_ext
|
102
|
+
#puts "Generating rule #{src_file} -> #{dst_file}"
|
103
|
+
file dst_file => src_file do |t|
|
104
|
+
yield [t, t.prerequisites[0]]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module RubySocialClub
|
4
|
+
|
5
|
+
=begin
|
6
|
+
This class splits all the rb files into snippet files.
|
7
|
+
|
8
|
+
A file like this
|
9
|
+
|
10
|
+
#!/usr/bin/ruby
|
11
|
+
|
12
|
+
#############<hello_world>#############
|
13
|
+
|
14
|
+
#!/usr/bin/ruby
|
15
|
+
|
16
|
+
3.times {puts 'Hello World'}
|
17
|
+
|
18
|
+
#############<hello_method>#############
|
19
|
+
|
20
|
+
#!/usr/bin/ruby
|
21
|
+
|
22
|
+
def ciao(nome)
|
23
|
+
puts "Ciao #{nome}"
|
24
|
+
end
|
25
|
+
|
26
|
+
ciao('Mario')
|
27
|
+
|
28
|
+
#############<hello_puts>#############
|
29
|
+
|
30
|
+
puts "Cosa è puts?"
|
31
|
+
puts("un semplice metodo")
|
32
|
+
|
33
|
+
Will produces 3 files. hello_world.rb, hello_method.rb and hello_puts.rb
|
34
|
+
=end
|
35
|
+
class Snippet
|
36
|
+
def initialize(filename)
|
37
|
+
@filename = filename
|
38
|
+
@content = []
|
39
|
+
end
|
40
|
+
|
41
|
+
def print(line)
|
42
|
+
@content << line
|
43
|
+
end
|
44
|
+
|
45
|
+
def strip
|
46
|
+
@content.pop until /[\S]/ =~ @content[-1]
|
47
|
+
@content.shift until /[\S]/ =~ @content[0]
|
48
|
+
end
|
49
|
+
|
50
|
+
def close
|
51
|
+
strip
|
52
|
+
text = @content.join('')
|
53
|
+
if (not File.exist?(@filename+'.rb')) or (File.read(@filename + '.rb') != text)
|
54
|
+
puts "Rewriting #{@filename}.rb"
|
55
|
+
File.open(@filename + '.rb', 'w') do | file |
|
56
|
+
file.print(text)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
puts "Skipped #{@filename}.rb because it was the same"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.snippettize_dir(src='.', out=File.join(src,'snippets'))
|
64
|
+
FileUtils.mkdir(out) unless Dir.exist? out
|
65
|
+
Dir[File.join(src, '*.rb')].each do | filename |
|
66
|
+
puts "Splitting #{filename}"
|
67
|
+
File.open(filename) do | file |
|
68
|
+
output = nil
|
69
|
+
file.each do | line |
|
70
|
+
line.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
71
|
+
if /^\s*\#+<\/>\#*\s*$/ =~ line
|
72
|
+
output.close if output
|
73
|
+
output = nil
|
74
|
+
elsif /^\s*\#+<(.*)>\#*\s*$/ =~ line
|
75
|
+
output.close if output
|
76
|
+
output = nil
|
77
|
+
output = Snippet.new(File.join(out, $1))
|
78
|
+
elsif output
|
79
|
+
output.print(line)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
output.close if output
|
83
|
+
end
|
84
|
+
end
|
85
|
+
out
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'RubySocialClub/convertor'
|
4
|
+
require 'FileUtils'
|
5
|
+
|
6
|
+
module RubySocialClub
|
7
|
+
describe "Convertor" do
|
8
|
+
|
9
|
+
def rb_file_convert_and_check(file, parse_xmp = false)
|
10
|
+
c = RubySocialClub::Convertor.new(file, parse_xmp)
|
11
|
+
latex = c.to_latex
|
12
|
+
latex.should_not be_nil
|
13
|
+
latex.encoding.should be(Encoding::UTF_8)
|
14
|
+
#"\xa4".should include(RubySocialClub::Convertor::SEPARATOR)
|
15
|
+
latex.split("\n").each do |line|
|
16
|
+
puts "Checkin line #{line}"
|
17
|
+
line[0].should == RubySocialClub::Convertor::SEPARATOR
|
18
|
+
line[-1].should == RubySocialClub::Convertor::SEPARATOR
|
19
|
+
end
|
20
|
+
latex
|
21
|
+
end
|
22
|
+
|
23
|
+
TMP_FOLDER = File.join('..','tmp')
|
24
|
+
TMP_SOURCE_DIR = File.join TMP_FOLDER, 'sources'
|
25
|
+
before :each do
|
26
|
+
FileUtils.rm_rf(TMP_FOLDER) if Dir.exist? TMP_FOLDER
|
27
|
+
FileUtils.cp_r('files/.', TMP_FOLDER)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should convert normal ruby file to latex source" do
|
31
|
+
file = File.join(TMP_SOURCE_DIR, 'object.rb')
|
32
|
+
rb_file_convert_and_check(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should convert irb ruby session to latex source" do
|
36
|
+
file = File.join(TMP_SOURCE_DIR, 'object.rb')
|
37
|
+
irb_xml = RubySocialClub::Convertor.prepare_irb_session file
|
38
|
+
#puts irb_xml
|
39
|
+
xmp_file = File.join(TMP_FOLDER, 'session.xmp.rb')
|
40
|
+
File.open(xmp_file, 'w') { |f| f << irb_xml }
|
41
|
+
latex = rb_file_convert_and_check(xmp_file, true)
|
42
|
+
#puts latex
|
43
|
+
latex.split("\n").each do |line|
|
44
|
+
if(line.include? '\XMPresult')
|
45
|
+
line.should match /\\XMPresult\{.+\}/
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "rake"
|
3
|
+
require 'FileUtils'
|
4
|
+
|
5
|
+
describe "app rake tasks" do
|
6
|
+
TMP_FOLDER = File.join('..','tmp')
|
7
|
+
TMP_SOURCE_DIR = File.join TMP_FOLDER, 'sources'
|
8
|
+
|
9
|
+
before do
|
10
|
+
FileUtils.rm_rf(TMP_FOLDER) if Dir.exist? TMP_FOLDER
|
11
|
+
FileUtils.cp_r('files/.', TMP_FOLDER)
|
12
|
+
|
13
|
+
@rake = Rake::Application.new
|
14
|
+
Rake.application = @rake
|
15
|
+
Rake.application.rake_require File.join("tmp", "rakefile")
|
16
|
+
Rake::Task.define_task(:environment)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "rake default" do
|
20
|
+
before do
|
21
|
+
@task_name = "default"
|
22
|
+
#YAML.stub!(:load_file).and_return([])
|
23
|
+
end
|
24
|
+
it "should have 'sources' and 'irb_sources' as a prereq" do
|
25
|
+
@rake[@task_name].prerequisites.should include("sources")
|
26
|
+
@rake[@task_name].prerequisites.should include("irb_sources")
|
27
|
+
end
|
28
|
+
it "should load 'config/options.yml'" do
|
29
|
+
YAML.should_receive(:load_file).with("config/options.yml").and_return([])
|
30
|
+
@rake[@task_name].invoke
|
31
|
+
end
|
32
|
+
it "should generate a tex file foreach rb file" do
|
33
|
+
@rake[@task_name].invoke
|
34
|
+
Dir[File.join(TMP_SOURCE_DIR, "*.tex")]
|
35
|
+
Dir[File.join(TMP_SOURCE_DIR, "*.tex")].size.should be == Dir[File.join(TMP_SOURCE_DIR, "*.rb")].size
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubySocialClub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,67 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2012-04-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &86136600 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *86136600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: syntax
|
27
|
+
requirement: &86136390 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *86136390
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &86136180 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *86136180
|
47
|
+
description: A tool for writing beamer presentation containig ruby code examples
|
15
48
|
email:
|
16
49
|
- nolith@abisso.org
|
17
|
-
executables:
|
18
|
-
- RubySocialClub
|
50
|
+
executables: []
|
19
51
|
extensions: []
|
20
52
|
extra_rdoc_files: []
|
21
53
|
files:
|
22
54
|
- .gitignore
|
23
55
|
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
24
58
|
- Rakefile
|
25
59
|
- RubySocialClub.gemspec
|
26
60
|
- bin/RubySocialClub
|
27
61
|
- lib/RubySocialClub.rb
|
62
|
+
- lib/RubySocialClub/convertor.rb
|
63
|
+
- lib/RubySocialClub/irbtorb.rb
|
64
|
+
- lib/RubySocialClub/rake_tasks.rb
|
65
|
+
- lib/RubySocialClub/snippet.rb
|
28
66
|
- lib/RubySocialClub/version.rb
|
29
|
-
|
67
|
+
- spec/convertor_spec.rb
|
68
|
+
- spec/files/rakefile.rb
|
69
|
+
- spec/files/sources/object.rb
|
70
|
+
- spec/rake_tasks_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
30
73
|
licenses: []
|
31
74
|
post_install_message:
|
32
75
|
rdoc_options: []
|
@@ -45,9 +88,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
88
|
- !ruby/object:Gem::Version
|
46
89
|
version: '0'
|
47
90
|
requirements: []
|
48
|
-
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.6
|
50
93
|
signing_key:
|
51
94
|
specification_version: 3
|
52
|
-
summary:
|
53
|
-
|
95
|
+
summary: This tool allows you to include real ruby example, with output, in latex
|
96
|
+
presentations.
|
97
|
+
test_files:
|
98
|
+
- spec/convertor_spec.rb
|
99
|
+
- spec/files/rakefile.rb
|
100
|
+
- spec/files/sources/object.rb
|
101
|
+
- spec/rake_tasks_spec.rb
|
102
|
+
- spec/spec_helper.rb
|