trecs 0.3.16 → 0.3.17

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: b2d987a423e2135d128e4bc58705d6cc15679269
4
- data.tar.gz: a4241d7f45696c816ca593663bb327d1131de9f2
3
+ metadata.gz: 36f09f6bf3ee384819705353885cd422b4fc3ee1
4
+ data.tar.gz: 78e0570a6a8b71479c391204a10a904e387215ff
5
5
  SHA512:
6
- metadata.gz: ca3b65d35f1a12db19714c71f109bcf430c8015a444ae00fc3486d11b2273e7fec1f1af218e7785d1790b37edc5983ba9976f1875e07b99f6d42cdaa0606d466
7
- data.tar.gz: 3c84eb972f87cca56ab69d9beb5fdf4b87fe6b7aa0a7e54bcbdcfc5ae3e7d3813dd6c9ae2b92a8b9e1647b34d8ed93754fe69f8092fb68dbdf186ebaf4fce462
6
+ metadata.gz: 28b35d6a1732c79b7788dd598e9e21214330935d0877d8ae2bd7e365a6fc05155d4626e87eb99132a957651b13da7f4d5fdb8f5f1db737056ce8f3e16ff8dcf8
7
+ data.tar.gz: ad73ab1c1b025c40f03c691c69459bbb4327e106670ecd7f34f60304136de2ab2023a5598f453c535571d4f902689adf22bba286ff7944fbfb1cdb3ab7f46e24
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.3.16)
4
+ trecs (0.3.17)
5
5
  minitar (~> 0.5.4)
6
6
  trollop (~> 2.0)
7
7
 
data/lib/trecs/frame.rb CHANGED
@@ -6,17 +6,17 @@ module TRecs
6
6
  def initialize(opts={})
7
7
  opts = opts.is_a?(Hash) ? opts : {content: opts}
8
8
  @content = opts.fetch(:content) { "" }
9
- @format = opts.fetch(:format) { "raw" }
9
+ @format = opts[:format] || "raw"
10
10
  end
11
11
 
12
12
  def width
13
- content.each_line.map { |line|
13
+ raw_text.each_line.map { |line|
14
14
  line.chomp.size
15
15
  }.max
16
16
  end
17
17
 
18
18
  def height
19
- content.lines.count
19
+ raw_text.lines.count
20
20
  end
21
21
 
22
22
  def each
@@ -34,11 +34,21 @@ module TRecs
34
34
  format: format
35
35
  }
36
36
  end
37
-
37
+
38
38
  def ==(other)
39
39
  other = Frame(other)
40
40
  to_s == other.to_s && format == other.format
41
41
  end
42
+
43
+
44
+ def raw_text
45
+ @raw_text = if format == "html"
46
+ content.split("\n").join("\\n").gsub(/<style>.+<\/style>/, "").gsub("\\n", "\n").gsub(%r{</?[^>]+?>}, '')
47
+ else
48
+ content
49
+ end
50
+ end
51
+ private
42
52
  end
43
53
 
44
54
  end
@@ -12,7 +12,9 @@ module TRecs
12
12
  attr_reader :trecs_backend
13
13
 
14
14
  def initialize(options={})
15
- @trecs_backend = options.fetch(:trecs_backend)
15
+ backend = options.fetch(:trecs_backend)
16
+ file = Pathname(backend).expand_path.to_s
17
+ @trecs_backend = file
16
18
  end
17
19
 
18
20
  def create_recording
@@ -1,21 +1,58 @@
1
1
  require "strategies/raw_file_strategy"
2
+ require "frame"
2
3
 
3
4
  module TRecs
4
5
  class EmacsPluginStrategy < RawFileStrategy
5
- def initialize(options={})
6
+ def initialize(options={})
6
7
  file = "/tmp/emacs-session-recording.html"
7
8
  @file = File.open(file)
8
9
 
9
10
  @clock = options.fetch(:clock) { Time }
10
11
  @testing = options.fetch(:testing) { false }
11
12
 
12
- current_format(:html)
13
+ @width = 0
14
+ @height = 0
13
15
  end
14
16
 
17
+ def perform
18
+ @recording = true
19
+ start_time = clock.now
20
+
21
+ frames = {}
22
+
23
+ while @recording
24
+ frames[timestamp(clock.now - start_time)] = File.read(@file)
25
+ custom_sleep(recorder.step)
26
+ end
27
+
28
+ frames.each do |_, content|
29
+ frame = Frame.new(content: content, format: "html")
30
+ @width = frame.width if frame.width > @width
31
+ @height = frame.height if frame.height > @height
32
+ end
33
+
34
+ frames.each do |time, content|
35
+ current_time(time)
36
+ current_content(content)
37
+ current_format("html")
38
+ save_frame
39
+ end
40
+ end
15
41
 
16
42
  def current_content(content=nil)
17
- content.gsub!(/body {\n/, "div.trecs-code {\n")
18
- super(content)
43
+ style = content.split("\n")
44
+ .join("\\n")[/<style type="text\/css">\\n <!--\\n (.+)\\n -->\\n <\/style>/, 1]
45
+ .split("\\n ").join("\n")
46
+ .gsub("body {", "pre.emacs-code {")
47
+ code = content
48
+ .split("\n").join("<do not compute>")[/\s+<pre>(.+)<\/pre>/, 1]
49
+ .split("<do not compute>").join("\n")
50
+ .gsub(/\/\*.+\*\//, "")
51
+ #.gsub!(/^\s/, "").gsub!(/^(<[^\/]\w+ (\w+=['"][^>]+['"])*>)+ /) {|m| m[-1]=""; m } # clean extra space at the begining of each line
52
+
53
+ new_content = "<style>#{style}</style><pre style='border: 2px solid #898989;width: #{@width}ex;height: #{@height}ex' class='emacs-code'>#{code}</pre>"
54
+
55
+ super(new_content)
19
56
  end
20
57
  end
21
58
  end
@@ -33,7 +33,7 @@ module TRecs
33
33
  end
34
34
 
35
35
  def save_frame
36
- options = {time: __time, content: __content, format: __format}
36
+ options = {time: __time, format: __format, content: __content}
37
37
  options.reject! {|k,v| v.nil?}
38
38
 
39
39
  recorder.current_frame(options)
@@ -33,7 +33,8 @@ module TRecs
33
33
  timestamps.each do |time|
34
34
  current_time(((time-from)/speed.to_f).to_i)
35
35
  current_content(frames[time])
36
- save_frame
36
+ current_format(frames[time].format)
37
+ save_frame if current_content
37
38
  end
38
39
  end
39
40
 
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.3.16"
2
+ VERSION = "0.3.17"
3
3
  end
@@ -25,13 +25,13 @@ module TRecs
25
25
  def create_frame(options={})
26
26
  time = options.fetch(:time)
27
27
  content = options.fetch(:content)
28
- format = options.fetch(:format) { nil }
28
+ format = options[:format]
29
29
 
30
30
  frame = {
31
31
  format: format,
32
32
  content: content,
33
33
  }
34
-
34
+
35
35
  frames[time] = frame
36
36
  end
37
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop