hdsl 1.0.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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hdsl.rb +70 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 337d031916cedb2b4156624d480b3c0f76d4165f
4
+ data.tar.gz: 375cac52ea6f9b461309d2de66268750929f3c06
5
+ SHA512:
6
+ metadata.gz: 31e6ab07d41cae1004f88ede13cd5d437a7e9c94a32e032b51d7be1036fa3f78b9e49955d1ac50f7be8edaf66ed047aea6a604708dae1f703496f44b133673cc
7
+ data.tar.gz: 3ce1c31fcca6632eb106eefcf0921b7da904f59028aab4e9798c782af7bb74840055d3a193575959560104f5eb84bafb6bc0cd2df91880d32fb6cbf470e8c105
data/lib/hdsl.rb ADDED
@@ -0,0 +1,70 @@
1
+ class HDSL
2
+ attr_reader :result
3
+ def initialize(&block)
4
+ instance_eval(&block)
5
+ end
6
+
7
+ def save(filename)
8
+ file = File.open(filename, 'w')
9
+ file.write @result
10
+ rescue IOError => e
11
+ puts "Could not open file for writing."
12
+ ensure
13
+ file.close unless file.nil?
14
+ end
15
+
16
+ #BEGIN special tags
17
+ #p is shorthand for "puts", so this must be used instead
18
+ def par(*args, &block)
19
+ tagstart 'p'
20
+ do_content *args, &block
21
+ tagend 'p'
22
+ end
23
+
24
+ def stylesheet(href)
25
+ @result ||= ''
26
+ @result << "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{href}\">"
27
+ end
28
+ #END special tags
29
+
30
+ private
31
+ def with_attr *args, &block
32
+ if block_given?
33
+ tagname, *attrs = *args
34
+ else
35
+ tagname, *attrs, content = *args
36
+ end
37
+
38
+ content = '' if !content
39
+
40
+ tagstart tagname + ' ' + attrs.join(' ')
41
+ do_content content, &block
42
+ tagend tagname
43
+ end
44
+
45
+ def tagstart tagname
46
+ @result ||= ''
47
+ @result << "<#{tagname}>"
48
+ end
49
+
50
+ def do_content *args, &block
51
+ content = args.first
52
+ if block_given?
53
+ instance_eval(&block)
54
+ else
55
+ @result << content unless !content
56
+ end
57
+ end
58
+
59
+ def tagend tagname
60
+ @result << "</#{tagname}>"
61
+ end
62
+
63
+ def method_missing(name, *args, &block)
64
+ tag = name.to_s
65
+
66
+ tagstart tag
67
+ do_content *args, &block
68
+ tagend tag
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hdsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Cornish
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: I got tired of writing HTML by hand at my webmaster job.
14
+ email: johncornishthe4th@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hdsl.rb
20
+ homepage: http://rubygems.org/gems/hdsl
21
+ licenses:
22
+ - GPL-3.0
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.10
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: DSL for easy HTML generation.
44
+ test_files: []