cablecar 0.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/bin/cablecar +205 -0
- data/cablecar.gemspec +27 -0
- data/lib/cablecar.rb +5 -0
- data/lib/cablecar/version.rb +3 -0
- data/shark/features/simple_compilation.feature +11 -0
- data/shark/features/simple_partial.feature +11 -0
- data/shark/test_files/_correct.html.erb +11 -0
- data/shark/test_files/_simple.html.erb +11 -0
- data/shark/test_files/_simple.mrb +11 -0
- data/shark/test_files/aboutus.mrb +11 -0
- data/shark/test_files/correct.html.erb +22 -0
- data/src/cablecar.rb +203 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14eb47d8e0211f7c7c317c63963870a3b0a133a3
|
4
|
+
data.tar.gz: 9df5a0ac64561acfb4b642509e6522b658e42876
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1d84dc571c01489bf1aef0776e0be128719878d5f4a8fe292e03ff67c86318dd3a18b9bd11cca1c3cc79e854692e14bdf28b807fca75a02cacc8617eb122b97
|
7
|
+
data.tar.gz: e25fa48ced597e663808fe7dd7362b45129b0c62fbefed20234cc2fcd0f65093e54e357cb7ef7e2405ea5504cf36a2f3b566c573b8c90b416230accef24a8f13
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Adhithya Rajasekaran
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adhithya Rajasekaran
|
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,58 @@
|
|
1
|
+
# Cablecar
|
2
|
+
|
3
|
+
Cablecar is a new Markdown based templating system for Rails which intends to replace ERB. It makes it as easy as
|
4
|
+
possible to write HTML templates without the complexities of HTML.
|
5
|
+
|
6
|
+
Cablecar uses .mrb file to define a template. Here is a sample template
|
7
|
+
|
8
|
+
```
|
9
|
+
# Why Cablecar?
|
10
|
+
|
11
|
+
**Cablecar** is super awesome. You should try it too.
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
Cablecar outputs the following output .html.erb file
|
16
|
+
|
17
|
+
|
18
|
+
```html
|
19
|
+
<html>
|
20
|
+
<head></head>
|
21
|
+
<body>
|
22
|
+
<h1>Why Cablecar?</h1>
|
23
|
+
<p><strong>Cablecar</strong> is super awesome. You should try it too. </p>
|
24
|
+
</body>
|
25
|
+
</html>
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
gem 'cablecar'
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install cablecar
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Cablecar has only one command. If you want to compile your MRB file into an ERB file, simply run
|
46
|
+
|
47
|
+
```
|
48
|
+
cablecar -c file.mrb
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/cablecar
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'slop'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'redcarpet'
|
6
|
+
|
7
|
+
class CablecarCompiler
|
8
|
+
|
9
|
+
def initialize(input_file_name)
|
10
|
+
|
11
|
+
@file_name = input_file_name
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def compile
|
16
|
+
|
17
|
+
def remove_embedded_ruby(input_string)
|
18
|
+
|
19
|
+
def find_all_matching_indices(input_string,pattern)
|
20
|
+
|
21
|
+
locations = []
|
22
|
+
|
23
|
+
index = input_string.index(pattern)
|
24
|
+
|
25
|
+
while index != nil
|
26
|
+
|
27
|
+
locations << index
|
28
|
+
|
29
|
+
index = input_string.index(pattern,index+1)
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
return locations
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
embedded_ruby_starting = find_all_matching_indices(input_string,"<%")
|
40
|
+
|
41
|
+
em_ruby_strings = []
|
42
|
+
|
43
|
+
embedded_ruby_starting.each do |starting|
|
44
|
+
|
45
|
+
string_extract = input_string[starting..-1]
|
46
|
+
|
47
|
+
em_ruby = string_extract.split("%>")[0] + "%>"
|
48
|
+
|
49
|
+
em_ruby_strings << em_ruby
|
50
|
+
|
51
|
+
input_string = input_string.sub(em_ruby,"$EmbedRB#{em_ruby_strings.index(em_ruby)+1}")
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
return input_string,em_ruby_strings
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def replace_embedded_ruby(input_string,embedded_ruby_strings)
|
60
|
+
|
61
|
+
embedded_ruby_strings.each_with_index do |em_ruby,index|
|
62
|
+
|
63
|
+
input_string = input_string.sub("$EmbedRB#{index+1}",em_ruby)
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
return input_string
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_file_name(input_path,file_extension)
|
72
|
+
|
73
|
+
extension_remover = input_path.split(file_extension)
|
74
|
+
|
75
|
+
remaining_string = extension_remover[0].reverse
|
76
|
+
|
77
|
+
path_finder = remaining_string.index("/")
|
78
|
+
|
79
|
+
remaining_string = remaining_string.reverse
|
80
|
+
|
81
|
+
unless remaining_string.include?("/")
|
82
|
+
|
83
|
+
return remaining_string
|
84
|
+
|
85
|
+
else
|
86
|
+
|
87
|
+
remaining_string[remaining_string.length-path_finder..-1]
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
|
94
|
+
|
95
|
+
contents = File.open(@file_name, "rb").read
|
96
|
+
|
97
|
+
contents,embedded_ruby = remove_embedded_ruby(contents)
|
98
|
+
|
99
|
+
unless find_file_name(@file_name,".mrb").include?("_")
|
100
|
+
|
101
|
+
rendered_file = "<html>\n\n<head></head>\n\n<body>\n\n" + markdown.render(contents) + "\n\n</body>\n\n</html>"
|
102
|
+
|
103
|
+
else
|
104
|
+
|
105
|
+
rendered_file = markdown.render(contents)
|
106
|
+
|
107
|
+
end
|
108
|
+
rendered_file = replace_embedded_ruby(rendered_file,embedded_ruby)
|
109
|
+
|
110
|
+
output_file = @file_name.sub(".mrb",".html.erb")
|
111
|
+
|
112
|
+
File.open(output_file, 'w') { |file| file.write(rendered_file) }
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
cablecar_version = "0.0.0.1"
|
120
|
+
|
121
|
+
def create_mac_executable(input_file)
|
122
|
+
|
123
|
+
def read_file_line_by_line(input_path)
|
124
|
+
|
125
|
+
file_id = open(input_path)
|
126
|
+
|
127
|
+
file_line_by_line = file_id.readlines()
|
128
|
+
|
129
|
+
file_id.close
|
130
|
+
|
131
|
+
return file_line_by_line
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
|
136
|
+
|
137
|
+
mac_file_path = input_file.sub(".rb","")
|
138
|
+
|
139
|
+
file_id = open(mac_file_path,"w")
|
140
|
+
|
141
|
+
file_id.write(mac_file_contents.join)
|
142
|
+
|
143
|
+
file_id.close
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
opts = Slop.parse do
|
148
|
+
|
149
|
+
on :c, :compile=, 'Compile MRB Templates'
|
150
|
+
|
151
|
+
on :v, :version, 'Cablecar Version' do
|
152
|
+
|
153
|
+
puts cablecar_version
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
on :h, :help, 'Help with Cablecar' do
|
158
|
+
|
159
|
+
puts "\n\nCablecar is a Markdown based templating system for Rails\n\n"
|
160
|
+
|
161
|
+
puts "Basic usage:\n\n"
|
162
|
+
|
163
|
+
puts "\tcablecar -h/--help\n"
|
164
|
+
|
165
|
+
puts "\tcablecar -v/--version\n"
|
166
|
+
|
167
|
+
puts "\tcablecar -c/--compile [file_name].mrb\n"
|
168
|
+
|
169
|
+
puts "\n\n\n"
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
on :b,:build,'Build Cablecar' do
|
174
|
+
|
175
|
+
file_path = Dir.pwd + "/src/cablecar.rb"
|
176
|
+
|
177
|
+
create_mac_executable(file_path)
|
178
|
+
|
179
|
+
FileUtils.mv("#{file_path[0...-3]}", "#{Dir.pwd}/bin/cablecar")
|
180
|
+
|
181
|
+
puts "Build Successful!"
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
unless opts[:compile].nil?
|
188
|
+
|
189
|
+
input = opts[:compile]
|
190
|
+
|
191
|
+
if input.include?(".mrb")
|
192
|
+
|
193
|
+
compiler = CablecarCompiler.new(input)
|
194
|
+
|
195
|
+
compiler.compile
|
196
|
+
|
197
|
+
puts "Compilation was successful!"
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
puts "Invalid file!"
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
data/cablecar.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cablecar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cablecar"
|
8
|
+
spec.version = Cablecar::VERSION
|
9
|
+
spec.authors = ["Adhithya Rajasekaran"]
|
10
|
+
spec.email = ["adhithyan15@gmail.com"]
|
11
|
+
spec.description = %q{A new templating system for Rails}
|
12
|
+
spec.summary = %q{Cablecar is a markdown based templating system for Rails which produces ERB templates.}
|
13
|
+
spec.homepage = "http://adhithyan15.github.com/cablecar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "shark"
|
24
|
+
spec.add_dependency "slop"
|
25
|
+
spec.add_dependency "redcarpet"
|
26
|
+
|
27
|
+
end
|
data/lib/cablecar.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Compiling a simple MRB file into .html.erb
|
2
|
+
Scenario: Input with a simple MRB file
|
3
|
+
Given the input file "aboutus.mrb"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "aboutus.html.erb"
|
6
|
+
The output file must equal "correct.html.erb"
|
7
|
+
|
8
|
+
Configurations:
|
9
|
+
|
10
|
+
~compiler => src/cablecar.rb
|
11
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Compiling a simple partial MRB file into .html.erb
|
2
|
+
Scenario: Input with a simple partial MRB file
|
3
|
+
Given the input file "_simple.mrb"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "_simple.html.erb"
|
6
|
+
The output file must equal "_correct.html.erb"
|
7
|
+
|
8
|
+
Configurations:
|
9
|
+
|
10
|
+
~compiler => src/cablecar.rb
|
11
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<h2>Welcome</h2>
|
2
|
+
|
3
|
+
<p>Programming Resources is a place for programmers to find code samples for commonly used programming routines. We are planning on adding examples from as many languages as possible. If you have any code tutorials that you want to donate to our site, please contact us using the contact tab.</p>
|
4
|
+
|
5
|
+
<h3>License</h3>
|
6
|
+
|
7
|
+
<p>All the code samples in this site are released under a Creative Commons Attribution-SA-NC License. You can find more information on this license at <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">http://creativecommons.org/licenses/by-nc-sa/3.0/us/</a>.</p>
|
8
|
+
|
9
|
+
<h3>Authors</h3>
|
10
|
+
|
11
|
+
<p>This resource is being written by Sri Madhavi Rajasekaran and Adhithya Rajasekaran.</p>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<h2>Welcome</h2>
|
2
|
+
|
3
|
+
<p>Programming Resources is a place for programmers to find code samples for commonly used programming routines. We are planning on adding examples from as many languages as possible. If you have any code tutorials that you want to donate to our site, please contact us using the contact tab.</p>
|
4
|
+
|
5
|
+
<h3>License</h3>
|
6
|
+
|
7
|
+
<p>All the code samples in this site are released under a Creative Commons Attribution-SA-NC License. You can find more information on this license at <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">http://creativecommons.org/licenses/by-nc-sa/3.0/us/</a>.</p>
|
8
|
+
|
9
|
+
<h3>Authors</h3>
|
10
|
+
|
11
|
+
<p>This resource is being written by Sri Madhavi Rajasekaran and Adhithya Rajasekaran.</p>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
## Welcome
|
2
|
+
|
3
|
+
Programming Resources is a place for programmers to find code samples for commonly used programming routines. We are planning on adding examples from as many languages as possible. If you have any code tutorials that you want to donate to our site, please contact us using the contact tab.
|
4
|
+
|
5
|
+
### License
|
6
|
+
|
7
|
+
All the code samples in this site are released under a Creative Commons Attribution-SA-NC License. You can find more information on this license at http://creativecommons.org/licenses/by-nc-sa/3.0/us/.
|
8
|
+
|
9
|
+
### Authors
|
10
|
+
|
11
|
+
This resource is being written by Sri Madhavi Rajasekaran and Adhithya Rajasekaran.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
## Welcome
|
2
|
+
|
3
|
+
Programming Resources is a place for programmers to find code samples for commonly used programming routines. We are planning on adding examples from as many languages as possible. If you have any code tutorials that you want to donate to our site, please contact us using the contact tab.
|
4
|
+
|
5
|
+
### License
|
6
|
+
|
7
|
+
All the code samples in this site are released under a Creative Commons Attribution-SA-NC License. You can find more information on this license at http://creativecommons.org/licenses/by-nc-sa/3.0/us/.
|
8
|
+
|
9
|
+
### Authors
|
10
|
+
|
11
|
+
This resource is being written by Sri Madhavi Rajasekaran and Adhithya Rajasekaran.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<head></head>
|
4
|
+
|
5
|
+
<body>
|
6
|
+
|
7
|
+
<h2>Welcome</h2>
|
8
|
+
|
9
|
+
<p>Programming Resources is a place for programmers to find code samples for commonly used programming routines. We are planning on adding examples from as many languages as possible. If you have any code tutorials that you want to donate to our site, please contact us using the contact tab.</p>
|
10
|
+
|
11
|
+
<h3>License</h3>
|
12
|
+
|
13
|
+
<p>All the code samples in this site are released under a Creative Commons Attribution-SA-NC License. You can find more information on this license at <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">http://creativecommons.org/licenses/by-nc-sa/3.0/us/</a>.</p>
|
14
|
+
|
15
|
+
<h3>Authors</h3>
|
16
|
+
|
17
|
+
<p>This resource is being written by Sri Madhavi Rajasekaran and Adhithya Rajasekaran.</p>
|
18
|
+
|
19
|
+
|
20
|
+
</body>
|
21
|
+
|
22
|
+
</html>
|
data/src/cablecar.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'slop'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'redcarpet'
|
4
|
+
|
5
|
+
class CablecarCompiler
|
6
|
+
|
7
|
+
def initialize(input_file_name)
|
8
|
+
|
9
|
+
@file_name = input_file_name
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile
|
14
|
+
|
15
|
+
def remove_embedded_ruby(input_string)
|
16
|
+
|
17
|
+
def find_all_matching_indices(input_string,pattern)
|
18
|
+
|
19
|
+
locations = []
|
20
|
+
|
21
|
+
index = input_string.index(pattern)
|
22
|
+
|
23
|
+
while index != nil
|
24
|
+
|
25
|
+
locations << index
|
26
|
+
|
27
|
+
index = input_string.index(pattern,index+1)
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
return locations
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
embedded_ruby_starting = find_all_matching_indices(input_string,"<%")
|
38
|
+
|
39
|
+
em_ruby_strings = []
|
40
|
+
|
41
|
+
embedded_ruby_starting.each do |starting|
|
42
|
+
|
43
|
+
string_extract = input_string[starting..-1]
|
44
|
+
|
45
|
+
em_ruby = string_extract.split("%>")[0] + "%>"
|
46
|
+
|
47
|
+
em_ruby_strings << em_ruby
|
48
|
+
|
49
|
+
input_string = input_string.sub(em_ruby,"$EmbedRB#{em_ruby_strings.index(em_ruby)+1}")
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
return input_string,em_ruby_strings
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def replace_embedded_ruby(input_string,embedded_ruby_strings)
|
58
|
+
|
59
|
+
embedded_ruby_strings.each_with_index do |em_ruby,index|
|
60
|
+
|
61
|
+
input_string = input_string.sub("$EmbedRB#{index+1}",em_ruby)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
return input_string
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def find_file_name(input_path,file_extension)
|
70
|
+
|
71
|
+
extension_remover = input_path.split(file_extension)
|
72
|
+
|
73
|
+
remaining_string = extension_remover[0].reverse
|
74
|
+
|
75
|
+
path_finder = remaining_string.index("/")
|
76
|
+
|
77
|
+
remaining_string = remaining_string.reverse
|
78
|
+
|
79
|
+
unless remaining_string.include?("/")
|
80
|
+
|
81
|
+
return remaining_string
|
82
|
+
|
83
|
+
else
|
84
|
+
|
85
|
+
remaining_string[remaining_string.length-path_finder..-1]
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
|
92
|
+
|
93
|
+
contents = File.open(@file_name, "rb").read
|
94
|
+
|
95
|
+
contents,embedded_ruby = remove_embedded_ruby(contents)
|
96
|
+
|
97
|
+
unless find_file_name(@file_name,".mrb").include?("_")
|
98
|
+
|
99
|
+
rendered_file = "<html>\n\n<head></head>\n\n<body>\n\n" + markdown.render(contents) + "\n\n</body>\n\n</html>"
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
rendered_file = markdown.render(contents)
|
104
|
+
|
105
|
+
end
|
106
|
+
rendered_file = replace_embedded_ruby(rendered_file,embedded_ruby)
|
107
|
+
|
108
|
+
output_file = @file_name.sub(".mrb",".html.erb")
|
109
|
+
|
110
|
+
File.open(output_file, 'w') { |file| file.write(rendered_file) }
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
cablecar_version = "0.0.0.1"
|
118
|
+
|
119
|
+
def create_mac_executable(input_file)
|
120
|
+
|
121
|
+
def read_file_line_by_line(input_path)
|
122
|
+
|
123
|
+
file_id = open(input_path)
|
124
|
+
|
125
|
+
file_line_by_line = file_id.readlines()
|
126
|
+
|
127
|
+
file_id.close
|
128
|
+
|
129
|
+
return file_line_by_line
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
|
134
|
+
|
135
|
+
mac_file_path = input_file.sub(".rb","")
|
136
|
+
|
137
|
+
file_id = open(mac_file_path,"w")
|
138
|
+
|
139
|
+
file_id.write(mac_file_contents.join)
|
140
|
+
|
141
|
+
file_id.close
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
opts = Slop.parse do
|
146
|
+
|
147
|
+
on :c, :compile=, 'Compile MRB Templates'
|
148
|
+
|
149
|
+
on :v, :version, 'Cablecar Version' do
|
150
|
+
|
151
|
+
puts cablecar_version
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
on :h, :help, 'Help with Cablecar' do
|
156
|
+
|
157
|
+
puts "\n\nCablecar is a Markdown based templating system for Rails\n\n"
|
158
|
+
|
159
|
+
puts "Basic usage:\n\n"
|
160
|
+
|
161
|
+
puts "\tcablecar -h/--help\n"
|
162
|
+
|
163
|
+
puts "\tcablecar -v/--version\n"
|
164
|
+
|
165
|
+
puts "\tcablecar -c/--compile [file_name].mrb\n"
|
166
|
+
|
167
|
+
puts "\n\n\n"
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
on :b,:build,'Build Cablecar' do
|
172
|
+
|
173
|
+
file_path = Dir.pwd + "/src/cablecar.rb"
|
174
|
+
|
175
|
+
create_mac_executable(file_path)
|
176
|
+
|
177
|
+
FileUtils.mv("#{file_path[0...-3]}", "#{Dir.pwd}/bin/cablecar")
|
178
|
+
|
179
|
+
puts "Build Successful!"
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
unless opts[:compile].nil?
|
186
|
+
|
187
|
+
input = opts[:compile]
|
188
|
+
|
189
|
+
if input.include?(".mrb")
|
190
|
+
|
191
|
+
compiler = CablecarCompiler.new(input)
|
192
|
+
|
193
|
+
compiler.compile
|
194
|
+
|
195
|
+
puts "Compilation was successful!"
|
196
|
+
|
197
|
+
else
|
198
|
+
|
199
|
+
puts "Invalid file!"
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cablecar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adhithya Rajasekaran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shark
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A new templating system for Rails
|
84
|
+
email:
|
85
|
+
- adhithyan15@gmail.com
|
86
|
+
executables:
|
87
|
+
- cablecar
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/cablecar
|
98
|
+
- cablecar.gemspec
|
99
|
+
- lib/cablecar.rb
|
100
|
+
- lib/cablecar/version.rb
|
101
|
+
- shark/features/simple_compilation.feature
|
102
|
+
- shark/features/simple_partial.feature
|
103
|
+
- shark/test_files/_correct.html.erb
|
104
|
+
- shark/test_files/_simple.html.erb
|
105
|
+
- shark/test_files/_simple.mrb
|
106
|
+
- shark/test_files/aboutus.mrb
|
107
|
+
- shark/test_files/correct.html.erb
|
108
|
+
- src/cablecar.rb
|
109
|
+
homepage: http://adhithyan15.github.com/cablecar
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.0.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Cablecar is a markdown based templating system for Rails which produces ERB
|
133
|
+
templates.
|
134
|
+
test_files: []
|