demeler 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78ba7b6bfdda638f607939e76629196ca4e65b94
4
- data.tar.gz: 085c93b898362e447f095f89eca635e8bbc34424
2
+ SHA256:
3
+ metadata.gz: 83e011122ab4169782c9042b2671f7cf965d8fe899cbe9b948a313d8ca1d0511
4
+ data.tar.gz: bd7b2f6406686f22e7d30fdf39bc38ec183af071545dded36e61d320bfcebf39
5
5
  SHA512:
6
- metadata.gz: a1c7b23b050b02a7fcea12917e53d13f263e63e6d07f833c2e58c8d402db4b86e94fdfb4f52823f6598c6e0338e1fc4d43b5308f03b5f5b276c837b25499e8a9
7
- data.tar.gz: 43950fd11a2c6ec04fd56eda154bd6e4b719ff2c198eda54ab897aebb408d5b968f683fc2f4cae84c7f0728ddc0a3f83835efdb492102ba2bace779f5e5f854a
6
+ metadata.gz: 795d5ae16e22aea295c32713bbe7f6f6cc5c3a5209e69e13087add2f65fff67b179a4ffd674866a2be57348b82c68da82b19305a1f88584f8049a49651faa27d
7
+ data.tar.gz: bed48a4a010c5f9b190c80ce986b7c0c6c60aefbb2815d1602c2d34a6028ea26455bb834cf746ac284ba12832337c4a34d0e339b42c9a0cc805d30fcf225fc6c
@@ -1,3 +1,7 @@
1
+ # 1.0.10
2
+
3
+ * Made some changes to the documentation. More planned.
4
+
1
5
  # 1.0.9
2
6
 
3
7
  * Fixed the `selected` test in the `select` statement generator to convert both parts to string, then compare. As it was, a FixNum in the data obj failed to compare with a string in the options list.
data/LICENSE.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  ## Copyright ©2017 Michael J. Welch, Ph.D.
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
7
- ###The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
7
+ ###The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
9
9
  ###THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Demeler Gem
2
2
 
3
- **Copyright (c) 2017 Michael J Welch, Ph.D. <mjwelchphd@gmail.com>**
3
+ **Copyright (c) 2017-2019 Michael J Welch, Ph.D. <mjwelchphd@gmail.com>**
4
4
 
5
- _NOTE: I appologize that the documentation isn't better than it is, but I'm running way behind in my work trying to make this into a gem in order to preserve and share it._
5
+ _NOTE: I apologize that the documentation isn't better than it is, but I'm running way behind in my work trying to make this into a gem in order to preserve and share it._
6
6
 
7
7
  All files in this distribution are subject to the terms of the MIT license.
8
8
 
@@ -16,6 +16,65 @@ The French word démêler means "to unravel," and that's sort of what this gem d
16
16
 
17
17
  This class doesn't depend on any particular framework, but I use it with Ruby Sequel.
18
18
 
19
+ # Review of HTML5
20
+
21
+ > In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system.[3] Berners-Lee specified HTML and wrote the browser and server software in late 1990. That year, Berners-Lee and CERN data systems engineer Robert Cailliau collaborated on a joint request for funding, but the project was not formally adopted by CERN. In his personal notes[4] from 1990 he listed[5] "some of the many areas in which hypertext is used" and put an encyclopedia first.
22
+
23
+ > The first publicly available description of HTML was a document called "HTML Tags", first mentioned on the Internet by Tim Berners-Lee in late 1991.[6][7] It describes 18 elements comprising the initial, relatively simple design of HTML. Except for the hyperlink tag, these were strongly influenced by SGMLguid, an in-house Standard Generalized Markup Language (SGML)-based documentation format at CERN. Eleven of these elements still exist in HTML 4.[8]
24
+
25
+ > HTML is a markup language that web browsers use to interpret and compose text, images, and other material into visual or audible web pages. -- Wikipedia <https://en.wikipedia.org/wiki/HTML>
26
+
27
+ ### HTML Tags
28
+
29
+ HTML tags are element names surrounded by angle brackets:
30
+
31
+ ```html
32
+ <opening-tag>content goes here<closing-tag>
33
+ ```
34
+
35
+ The paragraph tag is a simple example of such a tag. For example:
36
+
37
+ ```html
38
+ <p>This is a paragraph. Space will precede and follow this text to set it apart as a paragraph.</p>
39
+ ```
40
+
41
+ - HTML tags normally come in pairs like \<p> and \</p>.
42
+ - The first tag in a pair is the start or opening tag, the second tag is the end or closing tag.
43
+ - The end tag is written like the start tag, but with a forward slash inserted before the tag name.
44
+ - Some tags don't require a content, so they can be written in a shorthand notation omitting the closing tag thusly: \<input ... />.
45
+ - Some tags don't require a closing tag, like \<br>, but Demeler will generate these in the shorthand form \<br />.
46
+
47
+ <https://www.w3schools.com/html/html_intro.asp>
48
+
49
+ #### Example of a Simple HTML Page
50
+
51
+ ```HTML
52
+ <!DOCTYPE html>
53
+ <html>
54
+ <head>
55
+ <title>Page Title</title>
56
+ </head>
57
+ <body>
58
+ <h1>My First Heading</h1>
59
+ <p>My first paragraph.</p>
60
+ </body>
61
+ </html>
62
+ ```
63
+
64
+ #### Example Explained
65
+
66
+ - The \<!DOCTYPE html> declaration defines this document to be HTML5
67
+ - The \<html> element is the root element of an HTML page
68
+ - The \<head> element contains meta information about the document
69
+ - The \<title> element specifies a title for the document
70
+ - The \<body> element contains the visible page content
71
+ - The \<h1> element defines a large heading
72
+ - The \<p> element defines a paragraph
73
+ - HTML is usually indented for readability, but does not require indentation, or even new lines (CR-LF or LF).
74
+
75
+ If you are reading this document, it is supposed that you are already familiar with HTML.
76
+
77
+ # Introduction to Demeler Gem
19
78
 
20
79
  ## The Demeler gem generates HTML from three inputs:
21
80
  * A Ruby source file you write;
@@ -26,20 +85,15 @@ Let's start with the most basic form, a simple example. Run `irb` and enter this
26
85
 
27
86
  ```ruby
28
87
  require 'demeler'
29
- html = Demeler.build(nil,true) do
88
+ html = Demeler.build(nil, true) do
30
89
  html do
31
- head do
32
- title "Hello, World!"
33
- end
34
- body do
35
- h1 "Hello, World!"
36
- end
90
+ head { title("Hello, World!") }
91
+ body { h1("Hello, World!") }
37
92
  end
38
- end
39
- puts html
93
+ end; puts html
40
94
  ```
41
95
 
42
- You'll get the html code like this:
96
+ You'll get HTML code like this:
43
97
 
44
98
  ```html
45
99
  <!-- begin generated output -->
@@ -54,15 +108,13 @@ You'll get the html code like this:
54
108
  <!-- end generated output -->
55
109
  ```
56
110
 
57
- ### Why bother with Demeler? Why not just write HTML?
111
+ The first argument (`nil`) is the `object`: we'll talk about that later. The second argument (`true`) tells Demeler to generate **formatted** HTML. Otherwise, you'll get a string like this:
58
112
 
59
- There are several reasons to use this gem:
113
+ ```html
114
+ <html><head><title>Hello, World!</title></head><body><h1>Hello, World!</h1></body></html>
115
+ ```
60
116
 
61
- * You write in Ruby code
62
- * Demeler balances out all the HTML tags
63
- * Demeler optionally formats the HTML, producing human readable output
64
- * Demeler can receive an object with data (such as a Sequel::Model object), and automatically insert the values
65
- * Demeler can insert error messages your controller inserts into the object
117
+ Unformated is usually preferred for production, as it produces slightly more compact output (but really, it's not a big deal for small files).
66
118
 
67
119
  ## You can also use the gem directly
68
120
 
@@ -82,6 +134,16 @@ end
82
134
  puts d.to_html
83
135
  ```
84
136
 
137
+ ### Why bother with Demeler? Why not just write HTML?
138
+
139
+ There are several reasons to use this gem:
140
+
141
+ * You write in Ruby code
142
+ * Demeler balances out all the HTML tags
143
+ * Demeler optionally formats the HTML, producing human readable output
144
+ * Demeler can receive an object with data (such as a Sequel::Model object), and automatically insert the values into your HTML
145
+ * Demeler can insert error messages into the object from your Ruby code, if there is an error
146
+
85
147
  ## Passing Variables into Demeler
86
148
 
87
149
  There are three variables you'll be interested in in Demeler.
@@ -94,7 +156,7 @@ For example,
94
156
 
95
157
  ```ruby
96
158
  countries = ['USA', 'Canada', 'France']
97
- Demeler.build(nil, true, countries) do
159
+ html = Demeler.build(nil, true, countries) do
98
160
  p usr.inspect
99
161
  end
100
162
  ```
@@ -102,7 +164,7 @@ end
102
164
  will generate:
103
165
 
104
166
  ```html
105
- <!-- begin generated output -->
167
+ <!-- begin generated output -->
106
168
  <p>["USA", "Canada", "France"]</p>
107
169
  <!-- end generated output -->
108
170
  ```
@@ -129,7 +191,7 @@ The output is
129
191
 
130
192
  ## Fields from an object can be inserted automatically
131
193
 
132
- First, a word of warning: if you use variables other than those below, you script will crash. If your script crashes, don't blame Demeler first; look in your script for variables that shouldn't be there.
194
+ First, a word of warning: if you use variables other than those below, your script will crash. If your script crashes, don't blame Demeler first; look in your script for variables that shouldn't be there.
133
195
 
134
196
  You can automatically load the values from a Sequel::Model object, or you can define an object and use it in place of Sequel. To define an object, use a definition similar to this:
135
197
 
@@ -269,13 +331,75 @@ In most cases, this can be achieved just by eliminating the {}; `p "Some text."
269
331
 
270
332
  This is because the solo string is converted to a :text argument automatically.
271
333
 
272
- ## How to create an input control
334
+ # Programming
335
+
336
+ ## How to create an HTML tag
337
+
338
+ Any non-input tag can be created using the tag name and the tag options, like:
339
+
340
+ ```ruby
341
+ <tag-name>(<tag-option-1>, <tag-option-2>, ...)
342
+ ```
343
+
344
+ And since Ruby allows you to omit the parenthesis, you can also write:
345
+
346
+ ```ruby
347
+ <tag-name> <tag-option-1>, <tag-option-2>, ...
348
+ ```
349
+
350
+ For example, a paragraph can be written as:
351
+
352
+ ```ruby
353
+ p("This is a paragraph.")
354
+ ```
355
+
356
+ or
357
+
358
+ ```ruby
359
+ p "This is a paragraph."
360
+ ```
361
+
362
+ If the tag requires a condition statement at the end, you'll need the parenthesis.
363
+
364
+ ```ruby
365
+ p("This paragraph may, or may not, be inserted into the HTML: #{obj.some_variable}.") unless obj.some_variable.nil?
366
+ ```
367
+
368
+ **_Note_** that to do this, you have to pass in an object (`obj`)or a hash (`usr`) with the value you are inserting into the string and testing. (See the examples.)
369
+
370
+ ## How to create an input tag
371
+
372
+ An input tag can be created using:
373
+
374
+ ```ruby
375
+ input(<name>, <options>)
376
+ ```
377
+
378
+ Where `name` is a ruby symbol such as :username or :password, and `options` can be any tag options allowed for that kind of input, such as :size for a :type=>"text" input tag.
379
+
380
+ For example:
381
+
382
+ ```ruby
383
+ input(:username, :type=>"text", :size=>30, :value=>"joe.e.razsolli")
384
+ ```
385
+
386
+ Or there is a shortcut for \<input> HTML. Just use the _tag type_ as the tag itself. For example:
387
+
388
+ ```ruby
389
+ text(:username, :size=>30, :value=>"joe.e.razsolli")
390
+ ```
391
+
392
+ This format makes the Demeler code a little easier to read and write.
393
+
394
+ <br/>
273
395
 
274
396
  A standard input control is just a tag and options. Take the `text` control, for example.
275
397
 
276
398
  `text :username, :size=>30, :value=>"joe.e.razsolli"` => `<input name="username" size="30" value="joe.e.razsolli" type="text" />`
277
399
 
278
- The button, color, date, datetime_local, email, hidden, image, month, number, password, range, reset, search, submit, tel, text, time, url, and week tags all work the that way.
400
+ **_NOTE_** The button, color, date, datetime_local, email, hidden, image, month, number, password, range, reset, search, submit, tel, text, time, url, and week tags all work the that way.
401
+
402
+ <br>
279
403
 
280
404
  The textarea control, on the other hand, puts it's value between the tags, so it uses a :text attribute instead of a :value attribute.
281
405
 
@@ -360,7 +484,7 @@ Clear resets the output variables in order to reuse Demeler without having to re
360
484
 
361
485
  ### method_missing(meth, *args, &block)
362
486
 
363
- This is a Ruby method which catches method calls that have no real method. For example, when you code a `body` tag, there is no method in Demeler to handle that, so it is caught be `missing_method`. Missing_method passes the call along to `tag_generator` to be coded.
487
+ This is a Ruby method which catches method calls that have no real method. For example, when you code a `body` tag, there is no method in Demeler to handle that, so it is caught by `missing_method`. Missing\_method passes the call along to `tag_generator` to be coded.
364
488
 
365
489
  Name | Type | Value
366
490
  ---- | ---- | -----
@@ -379,7 +503,7 @@ block | Proc | The block with your code.
379
503
 
380
504
  ### def alink(text, args={}, parms={})
381
505
 
382
- The `alink` method is a shortcut to build an `a` tag. You could also write a `a` tag like so:
506
+ The `alink` method is a shortcut to build an `a` tag. You could write an `a` tag like so:
383
507
 
384
508
  ```ruby
385
509
  Demeler.build do
@@ -387,7 +511,7 @@ Demeler.build do
387
511
  end
388
512
  ```
389
513
 
390
- but the alink method is a shortcut. Code it like this:
514
+ but the alink method is a shortcut which supports added features. Note that HTML tag attributes are coded into `args`, and parameters are coded into `parms`. The alink method allows you to add attributes easily. Code it like this:
391
515
 
392
516
  ```ruby
393
517
  Demeler.build do
@@ -395,23 +519,26 @@ Demeler.build do
395
519
  end
396
520
  ```
397
521
 
398
- Better yet, the `alink` method lets you easily add parameters. To do this, you have to place the args in curly brackets, then list your parameters at the end like so:
522
+ To add parameters, you have to place the attributes (in `args`) in curly brackets, then list your parameters at the end like so:
399
523
 
400
524
  ```ruby
401
- params={:id=>77}
402
- out =Demeler.build do
403
- alink("Jobs", {:href=>"jobs"}, :id=>params[:id], :job=>'commercial')
525
+ params={:id=>77} # a hypothetical value
526
+
527
+ Demeler.build do
528
+ alink("Review Jobs", {:href=>"jobs"}, :id=>params[:id], :job=>'commercial job')
404
529
  end
405
530
  ```
406
531
 
407
- The HTML generated will look like this:
532
+ The attribute `href` is coded as :html=>"jobs", where "jobs" is the link URL. The `:href` value could also be coded as `:jobs`. A quoted text is the customary way to code an `:href` value, however. The HTML generated will look like this:
408
533
 
409
534
  ```html
410
535
  <!-- begin generated output -->
411
- <a href="jobs?id=77&job=commercial">Jobs</a>
536
+ <a href="jobs?id=77&job=commercial+job">Jobs</a>
412
537
  <!-- end generated output -->
413
538
  ```
414
539
 
540
+ Notice also that the parameter value is escaped, i.e., reserved and "unsafe" characters (such as space) are changed to a URI form.
541
+
415
542
  Name | Type | Value
416
543
  ---- | ---- | -----
417
544
  text | String | The text to be inserted into the tag.
@@ -20,6 +20,8 @@
20
20
  # This class doesn't depend on any particular framework, but I use it with
21
21
  # Ruby Sequel.
22
22
 
23
+ require "cgi" # part of the Ruby std lib
24
+
23
25
  class Demeler
24
26
  attr_reader :out, :obj, :usr
25
27
 
@@ -143,7 +145,7 @@ class Demeler
143
145
  parms.each do |k,v|
144
146
  href << k.to_s
145
147
  href << '='
146
- href << v.to_s
148
+ href << CGI::escape(v.to_s)
147
149
  href << '&'
148
150
  end
149
151
  else
@@ -1,4 +1,4 @@
1
1
  module Version
2
- VERSION = "1.0.9"
3
- MODIFIED = "2017-09-11"
2
+ VERSION = "1.1.0"
3
+ MODIFIED = "2019-10-10"
4
4
  end
data/notes CHANGED
@@ -37,7 +37,7 @@ git push -u origin master
37
37
  #----------------------------------------
38
38
 
39
39
  # To upload the gem to rubygems.org
40
- gem push demeler-1.0.8.gem
40
+ gem push demeler-1.0.9.gem
41
41
 
42
42
  sudo gem install demeler
43
43
 
@@ -50,4 +50,3 @@ irb -Ilib
50
50
  require_relative 'lib/demeler'
51
51
  load './lib/demeler.rb'
52
52
 
53
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demeler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael J. Welch, Ph.D.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem takes your ruby input, plus an object such as a Sequel::Model
14
14
  object, and generates HTML code. If the object has values, they're inserted into
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  version: '0'
49
49
  requirements: []
50
50
  rubyforge_project:
51
- rubygems_version: 2.4.6
51
+ rubygems_version: 2.7.6
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Yet another HTML generator.