mustache_form 0.1.1 → 0.1.3

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: a6a3874eb1b2b591a7d98fc14b476ab3f16b8477
4
- data.tar.gz: 033d6ccab29e0813f1162a7f41308dec88135aa9
3
+ metadata.gz: 1e7a3e7f0799ba94da894f6fa0840cf3494a80d4
4
+ data.tar.gz: 2fe8498eb18012c4df44f885fd71af0f3957273d
5
5
  SHA512:
6
- metadata.gz: 003fa3e0f7f3532f118c0e3144ed216d2f6e176f676d3462f8473dfc428938d862dd415b2c65bbd6750b30ed8647c5aa084de9022dfff1138c0fc7bd1b0dfc3f
7
- data.tar.gz: e2b812055d236b4ad71e49cca805c91dc969067f76e7ecfb636f11c20c66884a66f5cca3e6c06f641069027836a6bf073ebb5b9739eea2c0db2f80638079c593
6
+ metadata.gz: b889fb68a570fe1d1316627555ab77d72b85795a13244bf8050bf38ac36dc77a67bf9fb67e933a786beaa735f6b8f87fab0c6210da8310ecbbab38df89f4f56f
7
+ data.tar.gz: a4094992cd5c36796c783eec395932fa12a0618d5387cf9aa0f3f5c1000f0cf0e2e726184687a0a09879ec7a7982951959388d6008eb73df4234c681239870ee
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # MustacheForm
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mustache_form`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This is a small library that adds a set of helper methods to Mustache view classes. Mustache allows complete
4
+ seperation of concerns with view templates. With Mustache, the typical view layer is split up into two sub-layers: a Ruby Class-based "view" and an HTML "template", so you can concentrate on crafting your HTML without polluting it with embedded Ruby logic. This separation also makes it easier to test your view-code. The helper module has wrapper methods for the basic rails form_tag and form_for helpers. The current version also has wrappers for the simple_form form_helpers as well.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ The idea initially was sparked off by a gist from (https://github.com/dbi) - Thanks!
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,7 +23,111 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ The best way to explain how to use this little gem is with a few code samples from an existing
27
+ project of mine.
28
+
29
+ Sample template file with a form...
30
+
31
+ ```
32
+ {{# labeled_simple_form }}
33
+ {{ alert }}
34
+
35
+ <fieldset>
36
+ <div class="input_row">
37
+ <div class="input_field">
38
+ <!--{{ first_name_label }}-->
39
+ {{ first_name_field }}
40
+ </div>
41
+
42
+ <div class="input_field">
43
+ {{ last_name_field }}
44
+ </div>
45
+
46
+ <div class="input_field">
47
+ {{ email_address_field }}
48
+ </div>
49
+
50
+ <div class="input_field">
51
+ {{ mobile_phone_field }}
52
+ </div>
53
+
54
+ <div class="input_field">
55
+ {{ home_number_field }}
56
+ </div>
57
+ </div>
58
+
59
+ <div class="buttons">
60
+ {{ submit_button }} {{ cancel_button }}
61
+ </div>
62
+ </fieldset>
63
+
64
+ {{/ labeled_simple_form }}
65
+ ```
66
+
67
+ Sample view class that goes along with the above template.
68
+
69
+ ```
70
+ module People
71
+ #
72
+ class New < FormView
73
+ include Wrapper::People::Form
74
+
75
+ def labeled_simple_form
76
+ custom_simple_form_for(@person, url: {controller: "people", action: "create"}) do |f|
77
+ simple_form_common(f)
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+ ```
84
+
85
+ The example code here is taken from one of my projects that is using the Stache gem and hence I have a small
86
+ class that wraps that gem.. which is what the above view class inherits from. The important piece here is the
87
+ included module "MustacheForm::FormHelper". This has all the smarts to wrap the standard rails form_helper methods
88
+ and also the simple_form ones which are also used in this example. You would simply include this module in your
89
+ view class..
90
+
91
+ ```
92
+ class FormView < ::Stache::Mustache::View
93
+ include MustacheForm::FormHelper
94
+ end
95
+ ```
96
+
97
+ Finally the form module that is included in the above New class. The form_helper yields to this method and
98
+ it returns a hash (data pair) with the field names and values that are then forwarded with the form_tag smarts
99
+ to the Mustache render method to finally create the complete view. The biggest win here being that we have complete
100
+ separation of concerns between the view class and the logicless Mustache template!
101
+
102
+ ```
103
+ module People
104
+ module Form
105
+
106
+ def simple_form_common(f)
107
+ {
108
+ first_name_field: f.input(:first_name),
109
+ last_name_field: f.input(:last_name),
110
+ email_address_field: f.input(:email_address),
111
+ mobile_phone_field: f.input(:mobile_phone),
112
+ home_phone_field: f.input(:home_phone),
113
+
114
+ # Submit
115
+ cancel_button: cancel_button,
116
+ submit_button: submit_button(f),
117
+ }
118
+ end
119
+
120
+ def submit_button(f)
121
+ object_name = f.object.class.to_s.underscore.pluralize
122
+ f.button :submit, t("#{object_name}.new.submit"), class: "#{PRIMARY_ACTION_BUTTON_CLASS}"
123
+ end
124
+
125
+ ```
126
+
127
+ #### NB: simple_form gem dependancy
128
+
129
+ This version has an inbuilt dependancy on the simple_form gem. I intend to remove this dependancy in the next
130
+ build and include an install generator that lets the user decide whether it should be included and enabled or not.
26
131
 
27
132
  ## Development
28
133
 
@@ -33,4 +138,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
138
  ## Contributing
34
139
 
35
140
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mustache_form.
36
-
@@ -1,3 +1,3 @@
1
1
  module MustacheForm
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  #
27
27
  # - gem related ones
28
28
  spec.add_development_dependency 'mustache'
29
+ spec.add_development_dependency 'simple_form'
29
30
  spec.add_development_dependency 'rack'
30
31
  spec.add_development_dependency 'rspec'
31
32
  spec.add_development_dependency 'rspec-given'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Forkin
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simple_form
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rack
71
85
  requirement: !ruby/object:Gem::Requirement