sept 1.3.0 → 1.4.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sept +46 -18
  3. data/lib/sept.rb +40 -5
  4. metadata +13 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 877a538c2d04ccdf7b6bb1835008707e7c51a6ea
4
- data.tar.gz: 05616b59c02b6cc45282a97143b0c1f1e4c7071b
3
+ metadata.gz: 975454ccdb264c314891b01818ca7bdf7e5f84ab
4
+ data.tar.gz: 66161ae4a0e167b286aaf34b3e68f5834ad1c349
5
5
  SHA512:
6
- metadata.gz: b7e491d390763c0efb8b88950b2234697e110b887bdf80f2a666d9bb9b487e6f8d1dd13c601b5b04a4412578ffa090a2c4c6f7008490936502777ec2338e759d
7
- data.tar.gz: a1cf48909ed536bc1d4ff23e6f6ef23a3b12679387f4fd3fd9b531113ec54eb3903ff56ee6f858db065c890090ce5476839d14a3547df9747118a910db4f410e
6
+ metadata.gz: 7423c55788b587d66e3750398106c8b7aa36d0a13403d043a70d47f44888a5aa745cd27436f43528a68a237a4c4a7185e9fe4ff2abc8448a719c078d482947a5
7
+ data.tar.gz: e7446316fbe8d43f9c0b7a12d6a344cfcc36d5b7f1011f52f67f8a63c23eda0c67267cb5beecde8e6cc77ae61a655442d873367d1403d033795adeef129abe80
data/bin/sept CHANGED
@@ -1,31 +1,59 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- %w(sept colorize).each { |f| require f }
3
+ %w(sept colorize json).each { |f| require f }
4
4
 
5
5
  if ARGV.length == 0
6
6
  puts "ERROR No arguments passed!".red
7
7
  else
8
8
  case ARGV[0]
9
- when "-h" # help
10
- puts 'S-Expression Powered Template HyperText Markup Language',
11
- 'To get version, run `sept -v`',
12
- 'To pass some data, run `sept -d <data> files...`',
13
- '<data> is a ruby hash ({:key => "value",})',
14
- 'To pass some data via file, run `sept -f <datafile> files...`',
15
- '<datafile> is a file with ruby hash',
16
- 'Be careful! Any ruby code can be passed along with hash,',
17
- 'validation coming soon'
18
- when "-v" # version
9
+ when '-h', '--help' # help
10
+ puts <<-TEXT
11
+ S-Expression Powered Template HyperText Markup Language
12
+
13
+ EXAMPLE
14
+ test.sept:
15
+ (html
16
+ (head
17
+ (title Example)
18
+ (style ".heading { color: red }"))
19
+ (body
20
+ ("h1 class='heading'" Example)
21
+ (p %{param})))
22
+
23
+ After running `sept -d {"param":"Paragraph"} test.sept` you will get
24
+ test.html file:
25
+ <html>
26
+ <head>
27
+ <title>Example</title>
28
+ <style>.heading { color: red }</style>
29
+ </head>
30
+ <body>
31
+ <h1 class="heading">Example</h1>
32
+ <p>Paragraph</p>
33
+ </body>
34
+ </html>
35
+
36
+ SHELL ARGUMENTS
37
+ sept -v, sept --version
38
+ Prints version and exits.
39
+ sept -h, sept --help
40
+ Prints this message and exit.
41
+ sept -d <data> <files>, sept --data <data> <files>
42
+ You pass JSON hash to <data> for parser to use as parameters.
43
+ <files> are filenames of files.
44
+ sept -f <json file> <files>, sept --file <json file> <files>
45
+ Same as above, but instead of JSON hash, you pass name name of the file
46
+ with JSON hash.
47
+ TEXT
48
+ when '-v', '--version'
19
49
  # TODO: fetch version from sept.gemspec automatically
20
- puts "SEPT HTML version 1.3.0"
21
- when "-d" # data
22
- # TODO: replace this with json
50
+ puts "SEPT HTML version 1.4.0"
51
+ when '-d', '--data'
23
52
  puts "Passed data as argument"
24
- sept = Sept.new(eval(ARGV[1]), ARGV[2..-1])
25
- when '-f' # file
26
- # TODO: replace this with json
53
+ sept = Sept.new JSON.parse(ARGV[1]), ARGV[2..-1]
54
+ when '-f', '-file'
27
55
  puts "Passed data as file"
28
- sept = Sept.new(eval(File.read ARGV[1]), ARGV[2..-1])
56
+ sept = Sept.new JSON.parse(File.read ARGV[1]), ARGV[2..-1]
29
57
  else
30
58
  puts "No passed data"
31
59
  sept = Sept.new({}, ARGV)
data/lib/sept.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w(sxp colorize).each { |f| require f }
1
+ %w(sxp colorize json).each { |f| require f }
2
2
 
3
3
  # Markup as it should have been
4
4
  # Write your page as s-expression structure
@@ -25,10 +25,10 @@ class Sept
25
25
 
26
26
  # Constructor. The only method you would need
27
27
  #
28
- # @param params [Hash] Hash with parameters. Keys are symbols, values are strings.
28
+ # @param params [Hash] Hash with parameters.
29
29
  # @params files_to_parse [Array] List of files program will try to parse
30
30
  def initialize(params, files_to_parse)
31
- @params = params
31
+ @params = params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
32
32
  @html = ''
33
33
 
34
34
  files_to_parse.each { |f| self.cook f }
@@ -91,9 +91,10 @@ class Sept
91
91
  node = []
92
92
  node[0] = file
93
93
  else
94
- @html << "<#{node[0]}>"
94
+ temp = self.unfold_tag node[0]
95
+ @html << "<#{temp}>"
95
96
  node[1..-1].each { |e| self.to_html e }
96
- @html << "</#{node[0].split(' ')[0]}>"
97
+ @html << "</#{temp.split(' ')[0]}>"
97
98
  end
98
99
  end
99
100
  else
@@ -102,5 +103,39 @@ class Sept
102
103
 
103
104
  @html
104
105
  end
106
+
107
+ # Function that unfolds dot-notation and hash-notation
108
+ # p.class.class-to#id onclick="..."
109
+ # 'p class="class class-too" id="id" onclick="..."'
110
+ # #id must be after .classes
111
+ #
112
+ # @param tag [String] String like `tag.class.class2#id other-arg=""`
113
+ # @return [String] Unfolded tag
114
+ def unfold_tag(tag)
115
+ halves = tag.split(' ')
116
+ half = halves[0]
117
+
118
+ id = ''
119
+ if half.include? '#'
120
+ temp = half.split('#')
121
+ id = temp[-1]
122
+ half = temp[0..-2].join('')
123
+ end
124
+
125
+ klass = ''
126
+ if half.include? '.'
127
+ temp = half.split('.')
128
+ klass = temp[1..-1].join(' ')
129
+ half = temp[0]
130
+ end
131
+
132
+ tag_name = half
133
+ ret = tag_name
134
+ ret << " class='#{klass}'" unless klass.empty?
135
+ ret << " id='#{id}'" unless id.empty?
136
+ ret << " #{halves[1]}" unless halves[1].nil?
137
+
138
+ ret
139
+ end
105
140
  end
106
141
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sept
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timur Ismagilov
@@ -10,12 +10,18 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: " Write your HTML pages like Lisp code. Support of included files,\n
14
- \ parameters. CLI utility provided.\n\n Example:\n ```\n (html\n (head\n
15
- \ (title \"Hello world\")\n (style \".class { color: blue }\"))\n (body\n
16
- \ (\"p class='class'\" \"Note that if a tag has attributes, they are expressed
17
- this way\")\n (p Cool?)\n (p \"This is %{param}\")))\n ```\n\n\t\tThen
18
- run:\n\t\t```\n\t\tsept -d '{:param=>\"Parameter\"}' file.sept\n\t\t```\n"
13
+ description: |2
14
+ Write your HTML pages like Lisp code. Support of included files,
15
+ parameters. CLI utility provided. Run `sept -h` for more info
16
+
17
+ (html
18
+ (head
19
+ (title "Hello world")
20
+ (style ".red { color: blue }"))
21
+ (body
22
+ (p.red#cool-and-good "Handy classes and ids. Id must be last")
23
+ ("p onclick='func()'" "Other attributes are expressed that way")
24
+ (p "This is %{param}")))
19
25
  email: bouncepaw2@ya.ru
20
26
  executables:
21
27
  - sept