placemat 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: d08bb0f9605debf93f94c713dc827a14a032090b
4
- data.tar.gz: 1a6eb3948cfa08beced3fc84bc33e039f285e119
3
+ metadata.gz: 6483b9cdbfb763bed4c460297b97a0d25f9f01de
4
+ data.tar.gz: db2bcb206cffe2d61ceeef98394af1ca1a4469f6
5
5
  SHA512:
6
- metadata.gz: 669fadacd8f90bd329830455208d46dfc0fa4e31f4c3910f276e35712e8b87cd534c3e2089a33eaffbd32db94e937f5dc0da2e3bfb1595bbae1c61ee4e92925b
7
- data.tar.gz: 49a36aba7d7fe29d569444c95de256e26ed4f2517f6da39852631bf127a644298eff9fe5a2f5df043e5d0a86f95e585ba7fab8ed5f308fd29b1d5269f4e03e40
6
+ metadata.gz: bc6f35fe942c1be825c9183f06dfd0f7028a87874e52977f0467925a15771edf95e604905173c4d740f2ca537cf599e11310c59623d5f5e55bdb74280c1fc794
7
+ data.tar.gz: 0b7a58ad8d2e7abe18804913bab817c30b93b207d2a579d1536f3d7d969e3066920e2e42e27d64864d7ab20e33b87464067cd2e9312bb73f1bc1583f2c099f96
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Placemat is a robust (maybe?) pre-processing language exclusively for HTML tables.
6
6
 
7
- As of V 0.1.0, Placemat can handle parsing of basic tables without attribute formatting on cells.
7
+ As of V 0.2.0, Placemat can handle parsing of basic tables as well as colspan and row span. Additionally classes and ids can be added to cell level tags. For future/planned updates see tickets marked with the "0 - TODO" tag.
8
8
 
9
9
  ## Installation
10
10
 
@@ -12,6 +12,8 @@ You can install this gem:
12
12
 
13
13
  $ gem install placemat
14
14
 
15
+ If you have issues run the above code with "sudo"
16
+
15
17
  ## Usage
16
18
 
17
19
  ### Running Placemat
@@ -96,6 +98,44 @@ A|B|C
96
98
 
97
99
  ```
98
100
 
101
+ **c[int] and r[int]**
102
+ The c and r arguments are used to specify colspan and rowspan respectively. For these, each is followed by an integer that indicates the value. If no intereger is given the value defaults to one (1).
103
+
104
+ ```
105
+ |Name ::c2
106
+ ID |First |Last
107
+ -----
108
+ 001 |Scrooge|McDuck
109
+ 002 |Huey |Duck ::r3
110
+ 003 |Dewey | ::X
111
+ 004 |Louie | ::X
112
+
113
+ ```
114
+
115
+ **Classes and Ids**
116
+ An argument may also be given in the block for a cell to give it
117
+ class attributes or an id. This is presented similar to a css selector.
118
+ So a cell like
119
+ ```
120
+ Hello ::.blue.underline#name_columns
121
+ ```
122
+ would translate to
123
+ ```
124
+ <td class="blue underline " id="name_columns">Hello</td>
125
+ ```
126
+ A more robust table may look like:
127
+
128
+ ```
129
+ |Name ::c2&.blue.underline#name_columns
130
+ ID |First |Last
131
+ -----
132
+ 001 |Scrooge|McDuck
133
+ 002 |Huey |Duck ::r3&#singleId
134
+ 003 |Dewey | ::X
135
+ 004 |Louie | ::X
136
+ ```
137
+
138
+
99
139
  #### Samples
100
140
  The /samples directory of this repo contains robust examples of creating tables with Placemat, including a table of the fully proposed formatting options for 1.0.0
101
141
 
@@ -32,6 +32,19 @@ class FileHandler
32
32
 
33
33
  end
34
34
 
35
+ ##
36
+ # Extends the String open class to allow quick retrieval of the first character
37
+ #
38
+ # @see http://stackoverflow.com/questions/2730854/ruby-how-to-get-the-first-character-of-a-string
39
+ class String #:nodoc:
40
+ def first #:nodoc:
41
+ self[0,1]
42
+ end
43
+ def trim_first #:nodoc:
44
+ self[1,self.length]
45
+ end
46
+ end
47
+
35
48
 
36
49
 
37
50
  require "placemat/PlmatToHTML_Converter"
@@ -6,7 +6,7 @@ OptionParser.new do |opts|
6
6
  plmat_parser.compile(plmat)
7
7
  end
8
8
  opts.on('--version', 'Display the version') do
9
- puts "0.1.0"
9
+ puts "0.2.0"
10
10
  exit
11
11
  end
12
12
  opts.on('-h', '--help', 'Display this help') do
@@ -83,7 +83,7 @@ class PlmatToHTML_Converter
83
83
  def strip_full_line_comments(raw_table_data) #:doc:
84
84
  raw_table_data = raw_table_data.split(/\n/)
85
85
  raw_table_data.each_with_index do |row, i|
86
- if row[0,1] == ";"
86
+ if row.first == ";"
87
87
  raw_table_data.delete_at(i)
88
88
  else
89
89
  raw_table_data[i] = trim_same_line_comments(row)
@@ -186,11 +186,59 @@ class PlmatToHTML_Converter
186
186
 
187
187
  ##
188
188
  # Builds tag attributes for a cell based on passed arguments
189
+ # If a value to value key code is present, it builds based on
190
+ # values in the local attr_keys hash, if not if checks for
191
+ # more complex intructions and passes to the appropriate method
189
192
  #
190
193
  # Arguments:
191
194
  # args (Array) - all arguments passed from the .plmat argument block
195
+ #
196
+ # Returns:
197
+ # (String) - string of formatted html attributes
192
198
  def build_cell_attrs(args) #:doc:
193
- ""
199
+ attrs = " "
200
+ attr_keys = Hash["r"=>"rowspan", "c"=>"colspan"]
201
+
202
+ args.each do |arg|
203
+ if attr_keys.has_key?(arg.first)
204
+ attrs += attr_keys[arg.first] + '="' + arg[1,arg.length] + '" '
205
+ else
206
+ attrs += parse_selectors(arg)
207
+ end
208
+ end
209
+ attrs
210
+ end
211
+
212
+ ##
213
+ # Parses a css-like selector string of class(es) and optionally
214
+ # an id (or ids? but don't do that) into their appropriate attribute strings
215
+ #
216
+ # Arguments:
217
+ # sel_str (String) - selector string
218
+ def parse_selectors(sel_str) #:doc:
219
+ classes = Array.new
220
+ ids = Array.new
221
+ attr_str= ""
222
+
223
+ sel_str = sel_str.gsub(/[\.\#]/, "." => "-.", "#" => "-#")
224
+ sel_str = sel_str[1,sel_str.length].split("-")
225
+
226
+ sel_str.each do |str|
227
+ if str.first == "."
228
+ classes.push(str.trim_first)
229
+ else
230
+ ids.push(str.trim_first)
231
+ end
232
+ end
233
+
234
+ if classes.length > 0
235
+ attr_str += 'class="' + classes.join(" ") + '" '
236
+ end
237
+ if ids.length > 0
238
+ attr_str += 'id="' + ids.join(" ") + '" '
239
+ end
240
+
241
+ attr_str
194
242
  end
195
243
 
196
244
  ##
@@ -1,3 +1,3 @@
1
1
  module Placemat #:nodoc:
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,31 +1,41 @@
1
1
  <table>
2
- <tr> <th>First Name</th><th>Last Name</th><th>Email</th> </tr>
2
+ <tr> <th >First Name</th><th >Last Name</th><th >Email</th> </tr>
3
3
 
4
- <tr> <td>Scrooge</td><td>McDuck</td><td>number1dime@example.net</td> </tr>
5
- <tr> <td>Launchpad</td><td>McQuack</td><td>lpad@example.org</td> </tr>
4
+ <tr> <td >Scrooge</td><td >McDuck</td><td >number1dime@example.net</td> </tr>
5
+ <tr> <td >Launchpad</td><td >McQuack</td><td >lpad@example.org</td> </tr>
6
6
  </table>
7
7
 
8
8
  <table>
9
- <tr> <th>First Name</th><th>Last Name</th><th>Email</th> </tr>
9
+ <tr> <th >First Name</th><th >Last Name</th><th >Email</th> </tr>
10
10
 
11
- <tr> <td>Scrooge</td><td>McDuck</td><td>number1dime@example.net</td> </tr>
12
- <tr> <td>Launchpad</td><td>McQuack</td><td>lpad@example.org</td> </tr>
11
+ <tr> <td >Scrooge</td><td >McDuck</td><td >number1dime@example.net</td> </tr>
12
+ <tr> <td >Launchpad</td><td >McQuack</td><td >lpad@example.org</td> </tr>
13
13
  </table>
14
14
 
15
15
  <table>
16
- <tr> <th>A</th><th>B</th><th>C</th> </tr>
16
+ <tr> <th >A</th><th >B</th><th >C</th> </tr>
17
17
 
18
- <tr> <td>1</td><td>2</td><td>3</td> </tr>
18
+ <tr> <td >1</td><td >2</td><td >3</td> </tr>
19
19
  </table>
20
20
 
21
21
  <table>
22
- <tr> <th>Customer ID</th><th>First Name</th><th>Last Name</th><th>email ; all rows above a line of pure hyphens (-) are treated as th</th> </tr>
23
-
24
- <tr> <td>0001</td><td>William Anderson </td><td>thewilliamanderson@gmail.com</td> </tr>
25
- <tr> <td>0002 </td><td>John</td><td>Doe</td><td>johndoe@example.com</td> </tr>
26
- <tr> <td>Scrooge</td><td>McDuck</td><td>scrooge@moneybin.net</td> </tr>
27
- <tr> <td>0003</td><td>William </td><td>Anderson</td><td>thewilliamanderson@gmail.com</td> </tr>
28
- <tr> <td>Multiple commands can be given after each with or without spaces lines starting with a tab are concatenated to the previous line with a space between them </td> </tr>
29
- <tr> <td>0004</td><td>Donald</td><td>Duck</td><td>donald.duck@gonavy.gov </td> </tr>
22
+ <tr> <th ></th><th colspan="2" class="blue underline" id="name_columns" >Name </th> </tr>
23
+ <tr> <th >ID</th><th >First</th><th >Last</th> </tr>
24
+
25
+ <tr> <td >001</td><td >Scrooge</td><td >McDuck</td> </tr>
26
+ <tr> <td >002</td><td >Huey</td><td rowspan="3" id="singleId" >Duck </td> </tr>
27
+ <tr> <td >003</td><td >Dewey</td> </tr>
28
+ <tr> <td >004</td><td >Louie</td> </tr>
29
+ </table>
30
+
31
+ <table>
32
+
33
+ <tr> <th >Customer ID</th><th >First Name</th><th >Last Name</th><th >email ; all rows above a line of pure hyphens (-) are treated as th</th> </tr>
34
+
35
+ <tr> <td >0001</td><td colspan="2" >Duckworth </td><td >butler@moneybin.net</td> </tr>
36
+ <tr> <td rowspan="2" >0002 </td><td >Scrooge</td><td >McDuck</td><td >scrooge@example.com</td> </tr>
37
+ <tr> <td >Scrooge</td><td >McDuck</td><td >scrooge@moneybin.net</td> </tr>
38
+ <tr> <td colspan="4" class="legal" rowspan="1" >Multiple commands can be given after each with or without spaces lines starting with a tab are concatenated to the previous line with a space between them </td> </tr>
39
+ <tr> <td >0004</td><td >Donald</td><td >Duck</td><td class="blue" >donald.duck@gonavy.gov </td> </tr>
30
40
  </table>
31
41
 
@@ -22,17 +22,26 @@ A|B|C
22
22
  -----
23
23
  1|this cell wont show ::X|2|3
24
24
 
25
+ ; sample of colspan
26
+ |Name ::c2&.blue.underline#name_columns
27
+ ID |First |Last
28
+ -----
29
+ 001 |Scrooge|McDuck
30
+ 002 |Huey |Duck ::r3&#singleId
31
+ 003 |Dewey | ::X
32
+ 004 |Louie | ::X
33
+
34
+
25
35
  ; a hyper-complex table, this uses the full proposed Placemat 1.0.0 spec
26
36
  Customer ID|First Name |Last Name |email ; all rows above a line of pure hyphens (-) are treated as th
27
37
  --------------------------------------------------------------------------
28
- 0001 |William Anderson ::c2 |thewilliamanderson@gmail.com ; ::arguments passes arguments to the cell, c[int] indicates colspan
29
- 0002 ::r2|John |Doe |johndoe@example.com ; the r[int] argument indicates row span
38
+ 0001 |Duckworth ::c2|butler@moneybin.net ; ::arguments passes arguments to the cell, c[int] indicates colspan
39
+ 0002 ::r2|Scrooge |McDuck |scrooge@example.com ; the r[int] argument indicates row span
30
40
  - ::X|Scrooge |McDuck |scrooge@moneybin.net ; the "X" argument means that the cell should not be rendered (aka, its a placeholder)
31
- 0003 |William ::.class#id|Anderson |thewilliamanderson@gmail.com ; haml syntax style for class and id appends
32
41
  Multiple commands can be given after each with or without spaces
33
42
  lines starting with a tab are concatenated to the previous line with
34
43
  a space between them
35
- ::c4&.legal &r2 ; Multiple arguments can be passed with the &, and spaces are removed from the argument block
44
+ ::c4&.legal&r1 ; Multiple arguments can be passed with the &, and spaces are removed from the argument block
36
45
  ; Any line that starts with a semi-colon should be ignored ; trailing white space should also be removed
37
46
  0004
38
47
  | Donald
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: placemat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Anderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler