sept 1.2.0
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 +7 -0
- data/lib/sept.rb +113 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a03df0b67e266bad1ede1071e07d84365ff0798b
|
|
4
|
+
data.tar.gz: 59058e4e21ef1b2bd85f807296f2e18e4d41e1cf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 860ed5624374fcddd5bed6d5683e4389b151659d09875499c3eccbc0ee059f5ec327a5132249be0b2da33a2d0ab9eeb34193ded6a73459df4520285f3d5ec985
|
|
7
|
+
data.tar.gz: 2092728efa0cefe9583cece36bff957743230d7a9d2d56495ec71259be7c7f2038bb7b01136514a27ded8a4f73e2827c7ec9e38f2e28528a22ed40e16dd8eef3
|
data/lib/sept.rb
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
%w(sxp colorize).each { |f| require f }
|
|
2
|
+
|
|
3
|
+
# Markup as it should have been
|
|
4
|
+
# Write your page as s-expression structure
|
|
5
|
+
# (html
|
|
6
|
+
# (head
|
|
7
|
+
# (title Hello World demo))
|
|
8
|
+
# (body
|
|
9
|
+
# (p Hello Wrold!)
|
|
10
|
+
# ("p class='para'" Attributes are also supported in this form)
|
|
11
|
+
# (table
|
|
12
|
+
# (tr
|
|
13
|
+
# (th What)
|
|
14
|
+
# (th Coolness %))
|
|
15
|
+
# (tr
|
|
16
|
+
# (td HTML)
|
|
17
|
+
# (td 0%))
|
|
18
|
+
# (tr
|
|
19
|
+
# (td SEPT)
|
|
20
|
+
# (td %{param})))))
|
|
21
|
+
class Sept
|
|
22
|
+
def initialize(params, files_to_parse)
|
|
23
|
+
@params = params
|
|
24
|
+
@html = ''
|
|
25
|
+
|
|
26
|
+
files_to_parse.each { |f| self.cook f }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def generate(file)
|
|
30
|
+
self.to_html(self.prepare(SXP.read(file))) % @params
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Function that 'cooks' passed file. It logs some info. The name is bad
|
|
34
|
+
def cook(filename)
|
|
35
|
+
unless File.extname(filename) == ".sept"
|
|
36
|
+
puts "#{filename} is not `.sept` file, so can't parse it!".red
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
@html = ''
|
|
40
|
+
|
|
41
|
+
file = File.read filename
|
|
42
|
+
puts "got #{filename}, its content is:\n#{file}"
|
|
43
|
+
|
|
44
|
+
new_filename = filename[0..-6] + ".html"
|
|
45
|
+
new_file = self.generate file
|
|
46
|
+
|
|
47
|
+
# Create file if it does not exist yet
|
|
48
|
+
File.new new_filename, 'w+' unless File.file? new_filename
|
|
49
|
+
File.write new_filename, new_file
|
|
50
|
+
puts "parsed #{filename} and saved in #{new_filename}:\n #{new_file}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Recursive function that turns everything in `node` to a string
|
|
54
|
+
# [:sym, [1, "str"]] => ["sym", ["1", "str"]]
|
|
55
|
+
def prepare(node)
|
|
56
|
+
node.each_with_index do |sub, i|
|
|
57
|
+
if sub.is_a? Array
|
|
58
|
+
self.prepare sub
|
|
59
|
+
else
|
|
60
|
+
node[i] = sub.to_s
|
|
61
|
+
if node[0] == "#include"
|
|
62
|
+
file = self.generate File.read node[1].to_s
|
|
63
|
+
node.pop until node.length == 0
|
|
64
|
+
node[0] = file
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Function that turns array to something usable
|
|
71
|
+
def to_html(node)
|
|
72
|
+
if node.is_a? Array
|
|
73
|
+
if node.length == 1 then @html << "<#{node[0]}/>"
|
|
74
|
+
else
|
|
75
|
+
@html << "<#{node[0]}>"
|
|
76
|
+
node[1..-1].each { |e| self.to_html e }
|
|
77
|
+
@html << "</#{node[0].split(' ')[0]}>"
|
|
78
|
+
end
|
|
79
|
+
else @html << node
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
@html
|
|
83
|
+
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
|
+
end
|
|
91
|
+
|
|
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
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sept
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Timur Isamgilov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Write your HTML pages like Lisp code. Support of included files, parameters.
|
|
14
|
+
CLI utility provided.
|
|
15
|
+
email: bouncepaw2@ya.ru
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/sept.rb
|
|
21
|
+
homepage: https://github.com/bouncepaw/sept
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.5.1
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: HTML templates as S-Expressions
|
|
45
|
+
test_files: []
|