rp 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/rp +7 -3
  2. data/lib/rp.rb +36 -20
  3. data/lib/rp/version.rb +1 -1
  4. metadata +1 -1
data/bin/rp CHANGED
@@ -2,9 +2,13 @@
2
2
  require 'Rp'
3
3
 
4
4
  if ARGV.any?
5
+ method = :to_html
6
+ if ARGV.include? '--rhtml'
7
+ method = :to_rhtml
8
+ end
5
9
  ARGV.each do |f|
6
- print Rp.parse(File.open(f, "r").each_line)
10
+ puts Rp.send(method, File.open(f, "r").each_line) unless f == '--rhtml'
7
11
  end
8
12
  else
9
- puts "Rp [file1] [file2] ..."
10
- end
13
+ puts "Rp [--rhtml] [file1] [file2] ..."
14
+ end
data/lib/rp.rb CHANGED
@@ -17,11 +17,32 @@ module Rp
17
17
  n.times {|i| @doc << "\n" << INDENT*(s-i) << "end"} if s >= 0
18
18
  end
19
19
 
20
+ def indent_and_ends l,i
21
+ ends @indent-1, @indent-i
22
+ @indent = i
23
+ @doc << "\n#{l}"
24
+ end
25
+
26
+ def indent_and_do l,i
27
+ @doc << " do\n#{l}"
28
+ @indent = i
29
+ end
30
+
31
+ def indent_line l,i
32
+ if i > @indent
33
+ indent_and_do l,i
34
+ elsif i < @indent
35
+ indent_and_ends l,i
36
+ else
37
+ @doc << "\n#{l}"
38
+ end
39
+ end
40
+
20
41
  def class_and_id l, i
21
42
  cls = ""
22
43
  id = ""
23
44
 
24
- parts = l.split(" ", 1)
45
+ parts = l.split(" ", 2)
25
46
  t1, t2 = parts[0].split("#")
26
47
  tmp = t1.split(".")
27
48
  tag_name = tmp.shift
@@ -54,28 +75,23 @@ module Rp
54
75
 
55
76
  if l[0..1] == CODE_MARK
56
77
  l.gsub!(/#{CODE_MARK} */, INDENT * i)
57
- @doc << "\n#{l}"
58
- next
59
- end
60
-
61
- l = class_and_id l, i
62
-
63
- if i > @indent
64
- # do
65
- @doc << " do\n" << l
66
- @indent = i
67
- elsif i < @indent
68
- # end
69
- ends @indent-1, @indent-i
70
- @indent = i
71
- @doc << "\n" << l
72
78
  else
73
- @doc << "\n" << l
79
+ l = class_and_id l, i
74
80
  end
75
- end
76
81
 
82
+ indent_line l,i
83
+ end
77
84
  ends(@indent-1, @indent)
78
- eval(@doc)
85
+ @doc
86
+ end
87
+
88
+ def to_html lines
89
+ eval(parse(lines))
90
+ end
91
+
92
+ def to_rhtml lines
93
+ parse(lines)
79
94
  end
80
95
  end
81
- # print Rp.parse(File.open(File.expand_path("../tmp/test.r")).readlines)
96
+ # puts Rp.to_rhtml(File.open(File.expand_path("../tmp/test1.r")).readlines)
97
+ # puts Rp.to_html(File.open(File.expand_path("../tmp/test1.r")).readlines)
@@ -1,3 +1,3 @@
1
1
  module Rp
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: