├── README.description ├── README.textile └── README.md /README.description: -------------------------------------------------------------------------------- 1 | Markup problems with textile and markdown 2 | ========================================= 3 | 4 | I started off using textile (see README.textile) and could 5 | not get the extended code block options to work. The only 6 | way I could get code blocks to work was by indenting 4 7 | space -- the traditional way -- but the use of the '@' or 8 | '~~~' didn't work. 9 | 10 | So I switched to markdown (see README.markdown) and so the 11 | '~~~' code blocks work, but now I can't get ordered lists 12 | to work properly. 13 | 14 | Furthermore, there seems to be no way to run my .md files 15 | through a GFM (github-flavored markdown) renderer to be able 16 | to test things: I'm forced to make a change, commit it, go 17 | to github, render it, see the problems and then start the 18 | cycle all over again ! 19 | 20 | I did find the old github "Live Preview" page, but that's deprecated 21 | (see http://github.github.com/github-flavored-markdown/preview.html). 22 | 23 | There's also another page tmpvar.com/markdown.html which does a 24 | pretty good job of rendering GFM, but it's not a precise fit. 25 | 26 | Questions: 27 | 1. Where's the complete documentation for how this stuff works? 28 | 2. Where's a REAL preview for this stuff? 29 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. simple_field 2 | 3 | simple_field allows you to write one view and then use that view for both show and create/update action. 4 | To accomplish this, you use the simple_field method in your view (it depends on simple_form) and then 5 | provide two shared views: 6 | 7 | @ shared/_simple_field.haml.html 8 | shared/_simple_field_show.haml.html 9 | @ 10 | which process the output appropriately. 11 | 12 | h2. Installation 13 | 14 | In Rails3, add this to your Gemfile 15 | bq.gem 'simple_field', :git => 'git@github.com:JESii/simple_field.git' 16 | and then run 17 | bq.bundle install 18 | 19 | h2. Getting Started 20 | 21 | Once you have installed the gem, define two views (haml, erb, or whatever templating system you are using) 22 | as described above. Here are examples designed for use with BlueprintCSS, simple_form, and haml that work on my system. 23 | bq.. 24 | ### shared/_simple_field.haml.html 25 | - form_field = form_field.to_sym 26 | %span{:class => "span-#{lspan}"} 27 | = f.label form_field 28 | %span{:class => "span-#{fspan} #{last}"} 29 | - if as.blank? then 30 | = f.input form_field, :label => false, :input_html => { :class => "form_field", :size => size } 31 | -else 32 | = f.input form_field, :as => "#{as.to_sym}", :label => false, :input_html => { :class => "form_field", :size => size } 33 | 34 | - form_field = form_field.to_sym 35 | %span{:class => "span-#{lspan}"} 36 | = f.label form_field 37 | %span{:class => "span-#{fspan} #{last}"} 38 | -result = f.object.send(form_field) 39 | -result = ' ' if result.nil? || result.to_s == '' 40 | -result = result.to_s.html_safe if result.respond_to? :to_s 41 | 42 | h2. Contributing to simple_field 43 | 44 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet 45 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it 46 | * Fork the project 47 | * Start a feature/bugfix branch 48 | * Commit and push until you are happy with your contribution 49 | * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 50 | * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. 51 | 52 | h2. Copyright 53 | 54 | Copyright (c) 2011 Jon Seidel. See LICENSE.txt for 55 | further details. 56 | 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple_field 2 | 3 | simple_field allows you to write one view and then use that view for both show and create/update actions. 4 | To accomplish this, you use the simple_field method in your view (it depends on simple_form) and then 5 | provide two shared views: 6 | 7 | ```ruby 8 | shared/_simple_field.haml.html 9 | shared/_simple_field_show.haml.html 10 | ``` 11 | which process the output appropriately. 12 | 13 | ## Installation 14 | 15 | In Rails3, add this to your Gemfile 16 | 17 | ```bash 18 | gem 'simple_field', :git => 'git@github.com:JESii/simple_field.git' 19 | ``` 20 | and then run 21 | 22 | ```bash 23 | bundle install 24 | ``` 25 | 26 | ## Getting Started 27 | 28 | simple_field allows the use of a single view (such as app/views/_form.html.haml) for both show and modify actions by determining 29 | if you are are in "display" (or "show") mode (e.g., read) or "modify" mode (e.g., create/update/delete) and then using one of two partials 30 | that you define: one for show mode and the other for modify mode. 31 | 32 | The code that is generated uses simple_form calls and positions the label and the actual form field using the 33 | blueprintCSS features, primarily the span class definitions. It assumes that you have a "label" and a "field", and allows 34 | you to position both elements precisely within the blueprint grid. The basic layout is as follows: 35 | 36 | | prefix | Label | middle | Field | 37 | 38 | where: 39 | * prefix - Empty space (i.e., number of empty grid elements) before the Label 40 | * Label - The label text, positioned in the desired number of grid elements 41 | * middle - Empty space (empty grid elements) between the Label and the Field 42 | * Field - The actual Field, either text (in show mode) or an input field (in modify mode), with defined grid positioning 43 | 44 | Using just simple_form and blueprint, you'd have to code something like this (using Haml instead of ERB): 45 | 46 | ```haml 47 | %span-2 48 |   49 | %span-2 50 | f.label form_field 51 | %span-1 52 |   53 | %span{:class => 'span-10 last'} 54 | f.input form_field, :label => false, :size => 25 55 | ``` 56 | 57 | (NOTE: the ' ' codes are there so that blueprint properly formats the grid; without them, the empty cells take up no space.) 58 | 59 | With simple_field, you code it like this: 60 | 61 | ```haml 62 | =simple_field(f, "Phone#", "phone_no", :ps => 2, :ls => 2, :ms => 1, :fs => 10, :size => "25", :last => true ) 63 | ``` 64 | where: 65 | * ps - prefix span size 66 | * ls - Label span size 67 | * ms - middle span size 68 | * fs - Field span size 69 | * size - Input field size 70 | * last - Blueprint's "last" field specification 71 | 72 | ## Shorthand for blueprint span specification 73 | 74 | Instead of coding all the options as hash entries (the :ps, :ls, ... entries), a shorthand notation is available: 75 | 76 | [Pn]Ln[Mx]Fn[L] 77 | 78 | where the [...] elements are optional and: 79 | * Pn - prefix span size 80 | * Ln - Label span size 81 | * Mn - middle span size 82 | * Fn - Field span size 83 | * L - Blueprint's "last" field specification 84 | 85 | Therefore, with the shorthand notation, you could instead code the following for the previous example: 86 | 87 | ```haml 88 | =simple_field f, "Phone#", "phone_no", P2L2M1F10L, :size => "25" 89 | ``` 90 | 91 | ## Partials for displaying the results 92 | 93 | The simple_field gem uses two partials to actually display each field, one for show actions and one for modify actions. The two views are described below: 94 | 95 | ### shared/_simple_field.haml.html 96 | 97 | ```haml 98 | - form_field = to_sym 99 | %span{:class => "span-#{lspan}"} 100 | = f.label form_field 101 | %span{:class => "span-#{fspan} #{last}"} 102 | - if as.blank? then 103 | = f.input form_field, :label => false, :input_html => { :class => "form_field", :size => size } 104 | -else 105 | = f.input form_field, :as => "#{as.to_sym}", :label => false, :input_html => { :class => "form_field", :size => size } 106 | ``` 107 | 108 | ### shared/_simple_field_show.haml.html 109 | 110 | ```haml 111 | - form_field = to_sym 112 | %span{:class => "span-#{lspan}"} 113 | = f.label form_field 114 | %span{:class => "span-#{fspan} #{last} form_field"} 115 | -result = f.object.send(form_field) 116 | -result = ' ' if result.nil? || result.to_s == '' 117 | -result = result.to_s.html_safe if result.respond_to? :to_s 118 | - if as.blank? then 119 | =result 120 | -else 121 | =result 122 | ``` 123 | 124 | ## Usage examples 125 | 126 | Once you have installed the gem, defined your two views (haml, erb, or whatever templating system you are using), added the 127 | simple_field partials, you're ready to start using it for view goodness. Here are some examples. 128 | 129 | ```haml 130 | .span-24 131 | =simple_field(f, "Driver", "drivers_name", :ls => 2, :fs => 10, :size => "25" ) 132 | =simple_field(f, "Company", "company_name", :ls => 2, :fs => 10, :size => "25", :last => true ) 133 | .span-24 134 | =simple_field(f, "Policy#", "policy_no", :ls => 2, :fs => 10, :size => "25" ) 135 | =simple_field(f, "Phone#", "phone_no", :ls => 2, :fs => 10, :size => "25", :last => true ) 136 | .span-24 137 | =simple_field(f, "Drv/L#", "drivers_license_no", :ls => 2, :fs => 10, :size => "15" ) 138 | =simple_field(f, "Truck No", "truck_no", :ls => 2, :fs => 10, :size => "10", :last => true ) 139 | 140 | .span-24 141 | .span-2.form_label 142 | Vehicle 143 | .span-22.last 144 | %p{ :style => "margin-top: 10px; margin-bottom: 0px; border-bottom: 2px solid #000;" } 145 | .span-24 146 | =simple_field(f, "Make", "vehicle_make", :ls => 2, :fs => 4, :size => "10" ) 147 | =simple_field(f, "Model", "vehicle_model", :ls => 2, :fs => 4, :size => "10" ) 148 | =simple_field(f, "Yr", "vehicle_year", :ls => 2, :fs => 4, :size => "10" ) 149 | =simple_field(f, "Vin", "vehicle_vin_no", :ls => 2, :fs => 4, :size => "15", :last => true ) 150 | ``` 151 | ## Contributing to simple_field 152 | 153 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet 154 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it 155 | * Fork the project 156 | * Start a feature/bugfix branch 157 | * Commit and push until you are happy with your contribution 158 | * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 159 | * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. 160 | 161 | ## Copyright 162 | 163 | Copyright (c) 2011 Jon Seidel. See LICENSE.txt for 164 | further details. 165 | --------------------------------------------------------------------------------