sept 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/lib/sept.rb +23 -31
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb1123d437cba85deb14a79a038dd0aa4b272e69
|
|
4
|
+
data.tar.gz: 1b2bede9ccc7260dc82f462ca0a5c7d507c1bb1b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad5998567dfdeedc9378f2d23ccdbf4aa6f8a579c5a103e587fe920c2d88df7de8d672bd4fbccecea745b2efc8cc38a1b387c878de0348bebc8e689032fe56f5
|
|
7
|
+
data.tar.gz: bedcbba640d5b9147b48eb9a0b38f4ac9e0e646ff87922df05ead2d3d9fdffb0355e390264a58719430a181960eb8247b43be83b281861d6976f9cab6c6f3da9
|
data/lib/sept.rb
CHANGED
|
@@ -18,7 +18,15 @@
|
|
|
18
18
|
# (tr
|
|
19
19
|
# (td SEPT)
|
|
20
20
|
# (td %{param})))))
|
|
21
|
+
# Learn more at:
|
|
22
|
+
# - https://rubygems.org/gems/sept
|
|
23
|
+
# - https://github.com/bouncepaw/sept
|
|
21
24
|
class Sept
|
|
25
|
+
|
|
26
|
+
# Constructor
|
|
27
|
+
#
|
|
28
|
+
# @param params [Hash] Hash with parameters. Keys are symbols, values are strings.
|
|
29
|
+
# @params files_to_parse [Array] List of files program will try to parse
|
|
22
30
|
def initialize(params, files_to_parse)
|
|
23
31
|
@params = params
|
|
24
32
|
@html = ''
|
|
@@ -26,11 +34,17 @@ class Sept
|
|
|
26
34
|
files_to_parse.each { |f| self.cook f }
|
|
27
35
|
end
|
|
28
36
|
|
|
37
|
+
# Method that generates ready HTML file from Sept file
|
|
38
|
+
#
|
|
39
|
+
# @param file [String] Sept file
|
|
40
|
+
# @return [String] HTML file
|
|
29
41
|
def generate(file)
|
|
30
42
|
self.to_html(self.prepare(SXP.read(file))) % @params
|
|
31
43
|
end
|
|
32
44
|
|
|
33
45
|
# Function that 'cooks' passed file. It logs some info. The name is bad
|
|
46
|
+
#
|
|
47
|
+
# @param filename [String] Name of file to 'cook'
|
|
34
48
|
def cook(filename)
|
|
35
49
|
unless File.extname(filename) == ".sept"
|
|
36
50
|
puts "#{filename} is not `.sept` file, so can't parse it!".red
|
|
@@ -50,14 +64,17 @@ class Sept
|
|
|
50
64
|
puts "parsed #{filename} and saved in #{new_filename}:\n #{new_file}"
|
|
51
65
|
end
|
|
52
66
|
|
|
53
|
-
# Recursive function that turns everything in `node` to a string
|
|
54
|
-
#
|
|
67
|
+
# Recursive function that turns everything in `node` to a string and handles
|
|
68
|
+
# including of other files (well, will handle)
|
|
69
|
+
#
|
|
70
|
+
# @param node [Array, String] A Sept node
|
|
55
71
|
def prepare(node)
|
|
56
72
|
node.each_with_index do |sub, i|
|
|
57
73
|
if sub.is_a? Array
|
|
58
74
|
self.prepare sub
|
|
59
75
|
else
|
|
60
76
|
node[i] = sub.to_s
|
|
77
|
+
# TODO: finish this thing
|
|
61
78
|
if node[0] == "#include"
|
|
62
79
|
file = self.generate File.read node[1].to_s
|
|
63
80
|
node.pop until node.length == 0
|
|
@@ -67,7 +84,10 @@ class Sept
|
|
|
67
84
|
end
|
|
68
85
|
end
|
|
69
86
|
|
|
70
|
-
#
|
|
87
|
+
# Recursive function that generates HTML string.
|
|
88
|
+
#
|
|
89
|
+
# @param node [Array, String] A Sept node
|
|
90
|
+
# @return [String]
|
|
71
91
|
def to_html(node)
|
|
72
92
|
if node.is_a? Array
|
|
73
93
|
if node.length == 1 then @html << "<#{node[0]}/>"
|
|
@@ -81,33 +101,5 @@ class Sept
|
|
|
81
101
|
|
|
82
102
|
@html
|
|
83
103
|
end
|
|
84
|
-
|
|
85
|
-
# Function that includes other files
|
|
86
|
-
# (#include file.sept) => contents of file.sept
|
|
87
|
-
def include_files(file)
|
|
88
|
-
|
|
89
|
-
end
|
|
90
104
|
end
|
|
91
105
|
|
|
92
|
-
ARGV.length == 0 ? puts("Too few arguments".red) : case ARGV[0]
|
|
93
|
-
when "-h" # help
|
|
94
|
-
puts 'S-Expression Powered Template HyperText Markup Language',
|
|
95
|
-
'To get version, run `sept -v`',
|
|
96
|
-
'To pass some data, run `sept -d <data> files...`',
|
|
97
|
-
'<data> is a ruby hash ({:key => "value",})',
|
|
98
|
-
'To pass some data via file, run `sept -f <datafile> files...`',
|
|
99
|
-
'<datafile> is a file with ruby hash',
|
|
100
|
-
'Be careful! Any ruby code can be passed along with hash,',
|
|
101
|
-
'validation coming soon'
|
|
102
|
-
when "-v" # version
|
|
103
|
-
puts "SEPT HTML version 1.2"
|
|
104
|
-
when "-d" # data
|
|
105
|
-
puts "Passed data as argument"
|
|
106
|
-
sept = Sept.new(eval(ARGV[1]), ARGV[2..-1])
|
|
107
|
-
when '-f' # file
|
|
108
|
-
puts "Passed data as file"
|
|
109
|
-
sept = Sept.new(eval(File.read ARGV[1]), ARGV[2..-1])
|
|
110
|
-
else
|
|
111
|
-
puts "No passed data"
|
|
112
|
-
sept = Sept.new({}, ARGV)
|
|
113
|
-
end
|