Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa86735
Showing
5 changed files
with
467 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="chrome=1"> | ||
<title>Proffer by hudge</title> | ||
|
||
<link rel="stylesheet" href="stylesheets/styles.css"> | ||
<link rel="stylesheet" href="stylesheets/pygment_trac.css"> | ||
<script src="javascripts/scale.fix.js"></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> | ||
<!--[if lt IE 9]> | ||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<header> | ||
<h1>Proffer</h1> | ||
<p>An Action Controller module to hide instance variables from views by default.</p> | ||
<p class="view"><a href="https://github.com/hudge/proffer">View the Project on GitHub <small>hudge/proffer</small></a></p> | ||
<ul> | ||
<li><a href="https://github.com/hudge/proffer/zipball/master">Download <strong>ZIP File</strong></a></li> | ||
<li><a href="https://github.com/hudge/proffer/tarball/master">Download <strong>TAR Ball</strong></a></li> | ||
<li><a href="https://github.com/hudge/proffer">Fork On <strong>GitHub</strong></a></li> | ||
</ul> | ||
</header> | ||
<section> | ||
<p><a href="http://travis-ci.org/hudge/proffer"><img src="https://secure.travis-ci.org/hudge/proffer.png?branch=master" alt="Build Status"></a></p> | ||
|
||
<p>A module to stop Action Controller from copying every instance variable available | ||
to an action to the view by default. Instead, Proffer provides a way to explicitly | ||
expose values as local variables within views.</p> | ||
|
||
<h3>Rationale</h3> | ||
|
||
<p>By default, Action Controller will make any instance variables present during an | ||
action available to its views (including partials). This effectively makes them | ||
global variables and can obscure their origin when maintaining views. Partials | ||
that exploit this behaviour can be particularly difficult to maintain as they | ||
may inherit state from their caller implicitly.</p> | ||
|
||
<p>We want to see if removing this default behaviour changes the way views are | ||
written. By forcing explicit declaration of dependencies, will better, more | ||
encapsulated design result?</p> | ||
|
||
<h3>Usage</h3> | ||
|
||
<p>Add the following to your <code>Gemfile</code>:</p> | ||
|
||
<div class="highlight"> | ||
<pre><span class="n">gem</span> <span class="s1">'proffer'</span> | ||
</pre> | ||
</div> | ||
|
||
|
||
<p>Include the <code>Proffer</code> module into any controllers you wish (include into | ||
<code>ApplicationController</code> to enforce this behaviour throughout your application):</p> | ||
|
||
<div class="highlight"> | ||
<pre><span class="k">class</span> <span class="nc">PostsController</span> <span class="o"><</span> <span class="no">ApplicationController</span> | ||
<span class="kp">include</span> <span class="no">Proffer</span> | ||
|
||
<span class="c1"># This will make a new Post object available as post in the view but</span> | ||
<span class="c1"># @heading will be nil.</span> | ||
<span class="k">def</span> <span class="nf">new</span> | ||
<span class="vi">@heading</span> <span class="o">=</span> <span class="s2">"New Post"</span> | ||
<span class="n">proffer</span> <span class="ss">:post</span> <span class="o">=></span> <span class="no">Post</span><span class="o">.</span><span class="n">new</span> | ||
<span class="k">end</span> | ||
<span class="k">end</span> | ||
</pre> | ||
</div> | ||
|
||
|
||
<p>Any proffered values will then be available to your views by their key:</p> | ||
|
||
<div class="highlight"> | ||
<pre><span class="cp"><%=</span> <span class="n">form_for</span><span class="p">(</span><span class="n">post</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="cp">%></span><span class="x"></span> | ||
<span class="x"> ...</span> | ||
<span class="cp"><%</span> <span class="k">end</span> <span class="cp">%></span><span class="x"></span> | ||
</pre> | ||
</div> | ||
|
||
|
||
<p>You can test your use of Proffer by inspecting the <code>proffered</code> method on your | ||
controllers instead of using <code>assigns</code> like so:</p> | ||
|
||
<div class="highlight"> | ||
<pre><span class="n">describe</span> <span class="no">FooController</span> <span class="k">do</span> | ||
<span class="n">describe</span> <span class="s2">"GET index"</span> <span class="k">do</span> | ||
<span class="n">it</span> <span class="s2">"only proffers the title"</span> <span class="k">do</span> | ||
<span class="n">get</span> <span class="ss">:index</span> | ||
<span class="n">controller</span><span class="o">.</span><span class="n">proffered</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="p">{</span> <span class="ss">:title</span> <span class="o">=></span> <span class="s2">"Title"</span> <span class="p">}</span> | ||
<span class="k">end</span> | ||
<span class="k">end</span> | ||
<span class="k">end</span> | ||
</pre> | ||
</div> | ||
|
||
|
||
<p>Note that if you set <code>@title</code> in a Proffer-enabled action, <code>assigns(:title)</code> | ||
will be <code>nil</code>.</p> | ||
|
||
<h3>Compatibility</h3> | ||
|
||
<p>As we rely on <code>ActionController#view_assigns</code>, this will only work with versions | ||
of Rails 3.0 or later. It is currently tested against Rails 3.2.</p> | ||
|
||
<h3>Disclaimer</h3> | ||
|
||
<p>We have not yet tried this in production so proceed with caution. This gem | ||
overrides <code>ActionController#view_assigns</code> and extends <code>ActionController#render</code>, | ||
so it may be incompatible with other gems that override these methods.</p> | ||
|
||
<h3>License</h3> | ||
|
||
<p>See LICENSE.txt</p> | ||
</section> | ||
<footer> | ||
<p>This project is maintained by <a href="https://github.com/hudge">hudge</a></p> | ||
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p> | ||
</footer> | ||
</div> | ||
<!--[if !IE]><script>fixScale(document);</script><!--<![endif]--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fixScale = function(doc) { | ||
|
||
var addEvent = 'addEventListener', | ||
type = 'gesturestart', | ||
qsa = 'querySelectorAll', | ||
scales = [1, 1], | ||
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; | ||
|
||
function fix() { | ||
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; | ||
doc.removeEventListener(type, fix, true); | ||
} | ||
|
||
if ((meta = meta[meta.length - 1]) && addEvent in doc) { | ||
fix(); | ||
scales = [.25, 1.6]; | ||
doc[addEvent](type, fix, true); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"Proffer","body":"[![Build Status](https://secure.travis-ci.org/hudge/proffer.png?branch=master)](http://travis-ci.org/hudge/proffer)\r\n\r\nA module to stop Action Controller from copying every instance variable available\r\nto an action to the view by default. Instead, Proffer provides a way to explicitly\r\nexpose values as local variables within views.\r\n\r\n### Rationale\r\n\r\nBy default, Action Controller will make any instance variables present during an\r\naction available to its views (including partials). This effectively makes them\r\nglobal variables and can obscure their origin when maintaining views. Partials\r\nthat exploit this behaviour can be particularly difficult to maintain as they\r\nmay inherit state from their caller implicitly.\r\n\r\nWe want to see if removing this default behaviour changes the way views are\r\nwritten. By forcing explicit declaration of dependencies, will better, more\r\nencapsulated design result?\r\n\r\n### Usage\r\n\r\nAdd the following to your `Gemfile`:\r\n\r\n```ruby\r\ngem 'proffer'\r\n```\r\n\r\nInclude the `Proffer` module into any controllers you wish (include into\r\n`ApplicationController` to enforce this behaviour throughout your application):\r\n\r\n```ruby\r\nclass PostsController < ApplicationController\r\n include Proffer\r\n\r\n # This will make a new Post object available as post in the view but\r\n # @heading will be nil.\r\n def new\r\n @heading = \"New Post\"\r\n proffer :post => Post.new\r\n end\r\nend\r\n```\r\n\r\nAny proffered values will then be available to your views by their key:\r\n\r\n```erb\r\n<%= form_for(post) do |f| %>\r\n ...\r\n<% end %>\r\n```\r\n\r\nYou can test your use of Proffer by inspecting the `proffered` method on your\r\ncontrollers instead of using `assigns` like so:\r\n\r\n```ruby\r\ndescribe FooController do\r\n describe \"GET index\" do\r\n it \"only proffers the title\" do\r\n get :index\r\n controller.proffered.should == { :title => \"Title\" }\r\n end\r\n end\r\nend\r\n```\r\n\r\nNote that if you set `@title` in a Proffer-enabled action, `assigns(:title)`\r\nwill be `nil`.\r\n\r\n### Compatibility\r\n\r\nAs we rely on `ActionController#view_assigns`, this will only work with versions\r\nof Rails 3.0 or later. It is currently tested against Rails 3.2.\r\n\r\n### Disclaimer\r\n\r\nWe have not yet tried this in production so proceed with caution. This gem\r\noverrides `ActionController#view_assigns` and extends `ActionController#render`,\r\nso it may be incompatible with other gems that override these methods.\r\n\r\n### License\r\n\r\nSee LICENSE.txt\r\n","tagline":"An Action Controller module to hide instance variables from views by default.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.highlight { background: #ffffff; } | ||
.highlight .c { color: #999988; font-style: italic } /* Comment */ | ||
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ | ||
.highlight .k { font-weight: bold } /* Keyword */ | ||
.highlight .o { font-weight: bold } /* Operator */ | ||
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */ | ||
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */ | ||
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */ | ||
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */ | ||
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ | ||
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */ | ||
.highlight .ge { font-style: italic } /* Generic.Emph */ | ||
.highlight .gr { color: #aa0000 } /* Generic.Error */ | ||
.highlight .gh { color: #999999 } /* Generic.Heading */ | ||
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ | ||
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */ | ||
.highlight .go { color: #888888 } /* Generic.Output */ | ||
.highlight .gp { color: #555555 } /* Generic.Prompt */ | ||
.highlight .gs { font-weight: bold } /* Generic.Strong */ | ||
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */ | ||
.highlight .gt { color: #aa0000 } /* Generic.Traceback */ | ||
.highlight .kc { font-weight: bold } /* Keyword.Constant */ | ||
.highlight .kd { font-weight: bold } /* Keyword.Declaration */ | ||
.highlight .kn { font-weight: bold } /* Keyword.Namespace */ | ||
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */ | ||
.highlight .kr { font-weight: bold } /* Keyword.Reserved */ | ||
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */ | ||
.highlight .m { color: #009999 } /* Literal.Number */ | ||
.highlight .s { color: #d14 } /* Literal.String */ | ||
.highlight .na { color: #008080 } /* Name.Attribute */ | ||
.highlight .nb { color: #0086B3 } /* Name.Builtin */ | ||
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */ | ||
.highlight .no { color: #008080 } /* Name.Constant */ | ||
.highlight .ni { color: #800080 } /* Name.Entity */ | ||
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */ | ||
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */ | ||
.highlight .nn { color: #555555 } /* Name.Namespace */ | ||
.highlight .nt { color: #000080 } /* Name.Tag */ | ||
.highlight .nv { color: #008080 } /* Name.Variable */ | ||
.highlight .ow { font-weight: bold } /* Operator.Word */ | ||
.highlight .w { color: #bbbbbb } /* Text.Whitespace */ | ||
.highlight .mf { color: #009999 } /* Literal.Number.Float */ | ||
.highlight .mh { color: #009999 } /* Literal.Number.Hex */ | ||
.highlight .mi { color: #009999 } /* Literal.Number.Integer */ | ||
.highlight .mo { color: #009999 } /* Literal.Number.Oct */ | ||
.highlight .sb { color: #d14 } /* Literal.String.Backtick */ | ||
.highlight .sc { color: #d14 } /* Literal.String.Char */ | ||
.highlight .sd { color: #d14 } /* Literal.String.Doc */ | ||
.highlight .s2 { color: #d14 } /* Literal.String.Double */ | ||
.highlight .se { color: #d14 } /* Literal.String.Escape */ | ||
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */ | ||
.highlight .si { color: #d14 } /* Literal.String.Interpol */ | ||
.highlight .sx { color: #d14 } /* Literal.String.Other */ | ||
.highlight .sr { color: #009926 } /* Literal.String.Regex */ | ||
.highlight .s1 { color: #d14 } /* Literal.String.Single */ | ||
.highlight .ss { color: #990073 } /* Literal.String.Symbol */ | ||
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */ | ||
.highlight .vc { color: #008080 } /* Name.Variable.Class */ | ||
.highlight .vg { color: #008080 } /* Name.Variable.Global */ | ||
.highlight .vi { color: #008080 } /* Name.Variable.Instance */ | ||
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */ | ||
|
||
.type-csharp .highlight .k { color: #0000FF } | ||
.type-csharp .highlight .kt { color: #0000FF } | ||
.type-csharp .highlight .nf { color: #000000; font-weight: normal } | ||
.type-csharp .highlight .nc { color: #2B91AF } | ||
.type-csharp .highlight .nn { color: #000000 } | ||
.type-csharp .highlight .s { color: #A31515 } | ||
.type-csharp .highlight .sc { color: #A31515 } |
Oops, something went wrong.