demeler 1.0.3 → 1.0.4

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: f45f975d6d264007855d0b65b8e99411c35ac272
4
- data.tar.gz: 16a199c800c43a2673ef63694988ff5ca1a97329
3
+ metadata.gz: 3903bce53b962d00a70df078d45ecc40b99cedfb
4
+ data.tar.gz: 5ca0c7cfb19aa5366695cab87f87313ae06522e3
5
5
  SHA512:
6
- metadata.gz: 057051d643c2387b0cf4234a5b221d9c73bb5b5e40750cb177bc5b4ebd9b7a213e90440e06df66d08b777ebff5101696a05230189a3fe91c3b633f2043d47360
7
- data.tar.gz: af215ceb16abeb57bb96741b88d8b4784eeb2b33f93b4c3148555c691704d746a22fa6dd6d6dfa96a5d89afe659966c2dde9498d6c98bad7410c3d5c276640fc
6
+ metadata.gz: 85133de7aebdb53534f25ae96bf0df604dcc82292e21cf413bc0a0c4e53d1a186687619e2370b197071f70668e9060990cabbd867be1ef7466f7590ace6fb92a
7
+ data.tar.gz: 4f0f0691707eecf112b03fea0d06b1d72a8b5c1c35e0a3e568c4259a753bb042d1bb0b0560ca70790de6be6f66599f7f68ce8e7422a144785d44cddd91eb2c27
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.4
2
+
3
+ * Added a `parms` argument to `alink` so that parameters that are being passed can be added as a hash. See the README.
4
+ * Added a test in specs to test the passing of parameters in `alink`.
5
+ * Updated the README and Notes.
6
+
1
7
  # 1.0.3
2
8
 
3
9
  * Updated the README and Notes.
data/README.md CHANGED
@@ -107,13 +107,12 @@ end
107
107
  <!-- end generated output -->
108
108
  ```
109
109
 
110
- If you have more than one thing to pass into Demeler, put your things into an Array or Hash. For example, say you have two lists of countries and cities.
110
+ If you have more than one thing to pass into Demeler, put your things into an Array or Hash. For example, say you have two lists of countries and cities, you can pass them in a hash (Ruby's default) like this:
111
111
 
112
112
  ```ruby
113
113
  countries = ['USA', 'Canada', 'France']
114
114
  cities = ['Los Angeles', 'Paris', 'Berlin']
115
- data = {:countries=>countries, :cities=>cities}
116
- Demeler.build(nil, true, data) do
115
+ Demeler.build(nil, true, :countries=>countries, :cities=>cities) do
117
116
  p usr[:countries].inspect
118
117
  p usr[:cities].inspect
119
118
  end
@@ -370,7 +369,7 @@ Name | Type | Value
370
369
  *args | Array | An array of arguments from the call that was intercepted. Tag_generator will try to make sense of them.
371
370
  block | Proc | The block with your code.
372
371
 
373
- ### def alink(text, args={})
372
+ ### def alink(text, args={}, parms={})
374
373
 
375
374
  The `alink` method is a shortcut to build an `a` tag. You could also write a `a` tag like so:
376
375
 
@@ -388,12 +387,28 @@ Demeler.build do
388
387
  end
389
388
  ```
390
389
 
391
- Yes, I know. Six of one, half-dozen of another. It had a legacy beginning, and I kept it in here.
390
+ 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:
391
+
392
+ ```ruby
393
+ params={:id=>77}
394
+ out =Demeler.build do
395
+ alink("Jobs", {:href=>"jobs"}, :id=>params[:id], :job=>'commercial')
396
+ end
397
+ ```
398
+
399
+ The HTML generated will look like this:
400
+
401
+ ```html
402
+ <!-- begin generated output -->
403
+ <a href="jobs?id=77&job=commercial">Jobs</a>
404
+ <!-- end generated output -->
405
+ ```
392
406
 
393
407
  Name | Type | Value
394
408
  ---- | ---- | -----
395
409
  text | String | The text to be inserted into the tag.
396
410
  *args | Hash | An hash of attributes which must include the :href attribute.
411
+ *parms | Hash | An hash of parameters to be passed when the link is clicked.
397
412
 
398
413
  ### def checkbox(name, opts, values)
399
414
 
data/lib/demeler.rb CHANGED
@@ -117,11 +117,25 @@ class Demeler
117
117
  # creating the 'a' tag.
118
118
  # @param [Proc] block
119
119
  #
120
- def alink(text, args={})Hash
120
+ def alink(text, args={}, parms={})Hash
121
121
  raise ArgumentError.new("In Demeler#alink, expected String for argument 1, text") if !text.kind_of?(String)
122
122
  raise ArgumentError.new("In Demeler#alink, expected Hash for argument 2, opts") if !args.kind_of?(Hash)
123
123
  raise ArgumentError.new("In Demeler#alink, expected an href option in opts") if !args[:href]
124
+
125
+ href = args.delete(:href).to_s
124
126
  opts = args.clone
127
+ if !parms.empty?
128
+ href << '?'
129
+ parms.each do |k,v|
130
+ href << k.to_s
131
+ href << '='
132
+ href << v.to_s
133
+ href << '&'
134
+ end
135
+ else
136
+ href << '&' # will be removed
137
+ end
138
+ opts[:href] = href[0..-2] # remove last '&'
125
139
  opts[:text] = text
126
140
  tag_generator(:a, opts)
127
141
  end
@@ -1,4 +1,4 @@
1
1
  module Version
2
- VERSION = "1.0.3"
3
- MODIFIED = "2017-06-12"
2
+ VERSION = "1.0.4"
3
+ MODIFIED = "2017-06-17"
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.2.gem
40
+ gem push demeler-1.0.4.gem
41
41
 
42
42
  sudo gem install demeler
43
43
 
data/spec/demeler.rb CHANGED
@@ -43,6 +43,12 @@ describe "Simple Demeler with no Object" do
43
43
  @d.to_s.should.equal "<a href=\"registration\">Registration</a>"
44
44
  end
45
45
 
46
+ it "should be a link with parameters" do
47
+ @d.clear
48
+ @d.alink("Registration", {:href=>"registration"}, :id=>77, :name=>"Mike")
49
+ @d.to_s.should.equal "<a href=\"registration?id=77&name=Mike\">Registration</a>"
50
+ end
51
+
46
52
  it "should be a plain checkbox control" do
47
53
  @d.clear
48
54
  @d.checkbox(:vehicle, {}, :volvo=>"Volvo", :saab=>"Saab", :mercedes=>"Mercedes", :audi=>"Audi")
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.3
4
+ version: 1.0.4
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-06-12 00:00:00.000000000 Z
11
+ date: 2017-06-17 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