SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
RuHL
                          How can I see with all that code in my view?




Wednesday, December 9, 2009
The first thought...
               Haml is so far away from HTML, why not take it further?


               Repeat content instead of having to write loops.


                %ul
                 - @school.special_features.each do |feature|
                   %li= feature.name



                # Maybe something like...
                %ul { repeat: special_features }
                   %li= feature.name




Wednesday, December 9, 2009
The next minute...
               I could actually pull this off with HTML.

                <ul ruby=”_collection: special_features”>
                 <li ruby=”name”/>
                </ul>


                # Which later changed to
                <ul>
                 <li data-ruhl =”_collection: special_features, name”/>
                </ul>

               ...more on this coming up




Wednesday, December 9, 2009
Thoughts from JSP days and beyond
               • Working with designers inefficient after converting views.
                 • Why convert the code from HTML to a language that generates HTML if
                     it is not necessary?


               • Views didn’t garner the same architecture attention ‘code’ did.
                 • Did formulating the Fat Model/Skinny Controller idea take everyone’s
                     energy?


               • Over time, code in views grew as quick fixes were applied.
                 • Little restrictions on what is allowed encourages misuse.

               • Testing views more difficult than models or controllers.
                 • Shouldn’t the multiple attempts to improve view testing be an indicator?



Wednesday, December 9, 2009
The 2 minute RuHL history.
               • The attribute was initially called ruby.
                 • Peter Cooper suggested data-ruby for HTML5 compliance.
                 • Coworker suggested data-ruhl to prevent potential naming collisions.

               • Crystallized the idea of ‘No code in views’
                 • This became the rule that could not be broken.

               • Should not have to code extra HTML tags to make something work.
                 • Exceptions to this arose and _swap was introduced. (details later)

               • Functionality to be driven by real use cases, not imagined scenarios.




Wednesday, December 9, 2009
Standalone RuHL
                   RuHL can be used outside Sinatra and Rails.

                   Ruhl::Engine.new(File.read(ʻhello_world.ruhlʼ)).render(self)


                   Breaking it down:
                      data = File.read(ʻhello_world.ruhlʼ)      # read the html file
                      engine = Ruhl::Engine.new(data)           # instantiate the engine
                      html = engine.render(self)                # render the html
                                                                # using self for context

                   In the Rails helper, self is the @template object available to the
                   controller. This gives you access to all the helpers available within the
                   view.



Wednesday, December 9, 2009
RuHL: _if
                  How would I conditionally display data?


                  #Don’t show the div or it’s contents if there aren’t users.
                    <div data-ruhl="_if: users?">
                       <table>
                         <thead>
                            <tr>
                              <td>First Name</td>
                              <td>Last Name</td>
                              <td>Email</td>
                            </tr>
                         </thead>
                         <tr data-ruhl="_collection: user_list">
                            <td data-ruhl="first_name">Andrew</td>
                            <td data-ruhl="last_name">Stone</td>
                            <td data-ruhl="email">andy@stonean.com</td>
                         </tr>
                       </table>
                     </div>




Wednesday, December 9, 2009
RuHL: _unless
                  How would I conditionally display data?


                  #Show the message if there aren’t users.
                    <p data-ruhl="_unless: users?">No Users were found.</p>


                  If users, the <p> tag would not be included on output.




Wednesday, December 9, 2009
RuHL: _use
               I want to use the user object as the local object within the scope of the div to
               simplify the calls. The methods will first be tried against the local object, then
               the global context.

                    <div data-ruhl="_use: current_user">
                       <h1> Editing <span data-ruhl="_swap: full_name"/></h1>
                       <table>
                         <thead>
                           <tr>
                              <td>First Name</td>
                              <td>Last Name</td>
                              <td>Email</td>
                           </tr>
                         </thead>
                         <tr>
                           <td data-ruhl="first_name">Andrew</td>
                           <td data-ruhl="last_name">Stone</td>
                           <td data-ruhl="email">andy@stonean.com</td>
                         </tr>
                       </table>
                     </div>




Wednesday, December 9, 2009
RuHL: _use
               So what about iterating over a collection?
                     <select id="states">
                       <option data-ruhl="_use: state_options">
                     </select>

               The option tag will be repeated for each item returned.
               state_options can return an array of hashes:
                  def state_options
                    [ {:value => 'AL', :inner_html => 'Alabama'},
                      {:value => 'AK', :inner_html => 'Alaska'},
                      {:value => 'AZ', :inner_html => 'Arizona'},
                      ...
                    ]
                  end

               :inner_html will set the contents of the tag. all other keys are treated as
               attributes for the tag.




Wednesday, December 9, 2009
RuHL: _swap
                  I have some template text, but want to replace content within a paragraph.


                  #Replace the span tag with the results of language
                    <p>The programming language, <span data-ruhl='_swap:language'/>, is awesome.</p>




Wednesday, December 9, 2009
RuHL: partials, layouts and params
                  <div id="page">
                    <div data-ruhl="_partial:file|header_search"/>
                    <div data-ruhl="_render_" class="metro"/>
                    <div data-ruhl="_partial:file|footer"/>
                  </div>


                  Can pass parameters to methods with a pipe (‘|’).


                  Use _render_ to get the =yield result in Rails. Defining the layout works as
                  expected within Rails. Outside of Rails, you pass a :layout option to the
                  engine constructor. The value of the :layout option is the path to the file.
                  Use :layout_source if you’ve cached the reading of the file (as Rails does).


                  Use _partial to pull in page partials. The method, in this case :file, must
                  return a path to the partial.




Wednesday, December 9, 2009
More information on keywords:


                        http://stonean.com/page/ruhl



                              Moving on. A lot to cover...


Wednesday, December 9, 2009
If the code isn’t in the view, where
                                          does it go?
               • RuHL encourages the use of the presenter pattern.
               • It’s easy with the helpers if you follow the convention in a
                  Rails app:
                  • Have presenter in app/presenters
                  • Name presenter similar to controller conventions (just
                     singular):
                              class UserPresenter < Ruhl::Rails::Presenter
                              end
                     (file name: user_presenter.rb)


Wednesday, December 9, 2009
What does my controller look like?
                  Controller methods look like:
                          def new
                            @post = Post.new

                            present
                          end



                         def create
                           @post = Post.new(params[:post])

                           if @post.save
                             flash[:notice] = 'Post was successfully created.'
                             redirect_to(@post)
                           else
                             present :new
                           end
                         end




Wednesday, December 9, 2009
And this works how?
                  For this example, let’s say we are working in the UsersController.


               • Calling present in the controller method creates a new instance of the
                  UserPresenter.
               • The UserPresenter instance is passed to the view as a local object.
               • RuHL will first apply all methods to the local object. If the local object does
                  not respond to the method, RuHL then tries to apply the method to the
                  context.
               • The context is everything you are accustomed to in a Rails view:
                  • Controller methods exposed with helper_method
                  • Helper methods (ApplicationHelper, UsersHelper)




Wednesday, December 9, 2009
And my model?
                  For this example, let’s say we are working with the UserPresenter.


                     • When the presenter is created, it has a local object called presentee
                        which holds the instance of the model you are presenting. (@user)
                     • If you have this call in your view:
                                              data-ruhl=”first_name”
                        the order is:
                        1. Does the presenter respond_to?(:first_name)
                              1. Does the presenter have first_name defined?
                              2.Does the presentee (@user) have first_name defined?
                        2.Try the method against the context
                              1. Raises exception if method not found.




Wednesday, December 9, 2009
So what about testing?
               • With RuHL, rendering your view is not required to test.
                 • Only interested in the correct placement and content of data-ruhl
                     attributes.
                  • Helper provided:
                <div class="single_box">
                  <h2>Topic: <span data-ruhl="_swap: name"/></h2>

                  <div id="chart">
                    <img data-ruhl="src: chart_period"/>
                  </div>
                </div>

                # To test above:

                it "calls to replace name" do
                  data_ruhl('div.single_box > h2 > span').should == "_swap: name"
                end




Wednesday, December 9, 2009
But wait, there’s more...
               Since RuHL encourages presenters, test your presenters as you would your
               models.


                                 This simplifies your testing!

               • Don’t have to go through your controller to trigger conditions that decide
                  the output in your view.
               • This decreases the amount of time required to run your tests.




Wednesday, December 9, 2009
Summary
               • Allowing code in your view is a bad practice.
                 • This simple requirement ensures a holistic approach.
               • Utilize the presenter pattern to hold the code you would otherwise have
                  placed in your view.
               • Using RuHL encourages continued designer involvement with the
                  maintenance of views.




Wednesday, December 9, 2009

Mais conteúdo relacionado

Mais procurados

Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingRobert Carr
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)kuydigital
 
Drupal 7 Theme System
Drupal 7 Theme SystemDrupal 7 Theme System
Drupal 7 Theme SystemPeter Arato
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Emma Jane Hogbin Westby
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Eugenio Minardi
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Absolute Beginners Guide to Drupal
Absolute Beginners Guide to DrupalAbsolute Beginners Guide to Drupal
Absolute Beginners Guide to DrupalRod Martin
 
ePUB 3 and Publishing e-books
ePUB 3 and Publishing e-booksePUB 3 and Publishing e-books
ePUB 3 and Publishing e-booksKerem Karatal
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modulestanoshimi
 
Intro to-html-backbone-angular
Intro to-html-backbone-angularIntro to-html-backbone-angular
Intro to-html-backbone-angularzonathen
 
MongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchMongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchWynn Netherland
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern PerlDave Cross
 
Customizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceCustomizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceBharat Chaudhari
 
Puppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfPuppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfDavid Danzilio
 

Mais procurados (20)

Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) Theming
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)
 
Drupal 7 Theme System
Drupal 7 Theme SystemDrupal 7 Theme System
Drupal 7 Theme System
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)
 
A look at Drupal 7 Theming
A look at Drupal 7 ThemingA look at Drupal 7 Theming
A look at Drupal 7 Theming
 
Drupal Front End PHP
Drupal Front End PHPDrupal Front End PHP
Drupal Front End PHP
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Absolute Beginners Guide to Drupal
Absolute Beginners Guide to DrupalAbsolute Beginners Guide to Drupal
Absolute Beginners Guide to Drupal
 
Design to Theme @ CMSExpo
Design to Theme @ CMSExpoDesign to Theme @ CMSExpo
Design to Theme @ CMSExpo
 
ePUB 3 and Publishing e-books
ePUB 3 and Publishing e-booksePUB 3 and Publishing e-books
ePUB 3 and Publishing e-books
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
Intro to-html-backbone-angular
Intro to-html-backbone-angularIntro to-html-backbone-angular
Intro to-html-backbone-angular
 
MongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchMongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouch
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
Customizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceCustomizing the look and-feel of DSpace
Customizing the look and-feel of DSpace
 
Puppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConfPuppet Design Patterns - PuppetConf
Puppet Design Patterns - PuppetConf
 

Destaque

130802 デザインマンホール蓋の世界とその楽しみ方
130802 デザインマンホール蓋の世界とその楽しみ方130802 デザインマンホール蓋の世界とその楽しみ方
130802 デザインマンホール蓋の世界とその楽しみ方Shouji Morimoto
 
How to give a kick ass demo
How to give a kick ass demoHow to give a kick ass demo
How to give a kick ass demostephenlead
 
Power Point 09 10 Formigues
Power Point 09 10 FormiguesPower Point 09 10 Formigues
Power Point 09 10 FormiguesCucaferatona
 
Performance Testing And Beyond
Performance Testing And BeyondPerformance Testing And Beyond
Performance Testing And BeyondPeter Brown
 
Evening in A Minor: Digital artwork by Shelley M. House
Evening in A Minor: Digital artwork by Shelley M. HouseEvening in A Minor: Digital artwork by Shelley M. House
Evening in A Minor: Digital artwork by Shelley M. HouseShelley House
 
HPM seminar5 ethics
HPM seminar5 ethicsHPM seminar5 ethics
HPM seminar5 ethicsSean Cubitt
 
Twitter for Real Estate Agents
Twitter for Real Estate AgentsTwitter for Real Estate Agents
Twitter for Real Estate AgentsBrad Sage
 
Hardware i Software
Hardware i SoftwareHardware i Software
Hardware i Softwarekaiser1616
 
Design Filter FIR
Design Filter FIRDesign Filter FIR
Design Filter FIRIbnu Fajar
 
Magazine Cover Evaluation
Magazine Cover EvaluationMagazine Cover Evaluation
Magazine Cover Evaluationguest6d3c71
 
privations / secretions
privations / secretionsprivations / secretions
privations / secretionsSean Cubitt
 
Nfib ny minimum wage study - 2012
Nfib ny minimum wage study - 2012Nfib ny minimum wage study - 2012
Nfib ny minimum wage study - 2012Unshackle Upstate
 
CBC: New York State Budget & Jobs Summit
CBC: New York State Budget & Jobs SummitCBC: New York State Budget & Jobs Summit
CBC: New York State Budget & Jobs SummitUnshackle Upstate
 
Resisitng Assimilation
Resisitng AssimilationResisitng Assimilation
Resisitng Assimilationranchman
 
Ssfootball
SsfootballSsfootball
Ssfootballjaenvit
 

Destaque (20)

130802 デザインマンホール蓋の世界とその楽しみ方
130802 デザインマンホール蓋の世界とその楽しみ方130802 デザインマンホール蓋の世界とその楽しみ方
130802 デザインマンホール蓋の世界とその楽しみ方
 
How to give a kick ass demo
How to give a kick ass demoHow to give a kick ass demo
How to give a kick ass demo
 
Atlas of NSW
Atlas of NSWAtlas of NSW
Atlas of NSW
 
Power Point 09 10 Formigues
Power Point 09 10 FormiguesPower Point 09 10 Formigues
Power Point 09 10 Formigues
 
Hpm8technology
Hpm8technologyHpm8technology
Hpm8technology
 
Performance Testing And Beyond
Performance Testing And BeyondPerformance Testing And Beyond
Performance Testing And Beyond
 
Evening in A Minor: Digital artwork by Shelley M. House
Evening in A Minor: Digital artwork by Shelley M. HouseEvening in A Minor: Digital artwork by Shelley M. House
Evening in A Minor: Digital artwork by Shelley M. House
 
HPM seminar5 ethics
HPM seminar5 ethicsHPM seminar5 ethics
HPM seminar5 ethics
 
Twitter for Real Estate Agents
Twitter for Real Estate AgentsTwitter for Real Estate Agents
Twitter for Real Estate Agents
 
Hardware i Software
Hardware i SoftwareHardware i Software
Hardware i Software
 
Design Filter FIR
Design Filter FIRDesign Filter FIR
Design Filter FIR
 
Ethics pres
Ethics presEthics pres
Ethics pres
 
Magazine Cover Evaluation
Magazine Cover EvaluationMagazine Cover Evaluation
Magazine Cover Evaluation
 
privations / secretions
privations / secretionsprivations / secretions
privations / secretions
 
Nfib ny minimum wage study - 2012
Nfib ny minimum wage study - 2012Nfib ny minimum wage study - 2012
Nfib ny minimum wage study - 2012
 
Book Talk
Book TalkBook Talk
Book Talk
 
03072010 Web
03072010 Web03072010 Web
03072010 Web
 
CBC: New York State Budget & Jobs Summit
CBC: New York State Budget & Jobs SummitCBC: New York State Budget & Jobs Summit
CBC: New York State Budget & Jobs Summit
 
Resisitng Assimilation
Resisitng AssimilationResisitng Assimilation
Resisitng Assimilation
 
Ssfootball
SsfootballSsfootball
Ssfootball
 

Semelhante a How can I see with all that code in my view

Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCRDrupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCRGaurav Mishra
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyBlazing Cloud
 
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal introEdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal introBryan Ollendyke
 
Introduction into Drupal site building
Introduction into Drupal site buildingIntroduction into Drupal site building
Introduction into Drupal site buildingIztok Smolic
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stacknuppla
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentsparkfabrik
 
drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010Florian Latzel
 
Decoupled drupal DcRuhr
Decoupled drupal DcRuhrDecoupled drupal DcRuhr
Decoupled drupal DcRuhrAhmad Hassan
 
Making The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowMaking The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowPhilip Norton
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Mir Nazim
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleJohan Gant
 
Drupal
DrupalDrupal
Drupalbtopro
 
Drupal module development training delhi
Drupal module development training delhiDrupal module development training delhi
Drupal module development training delhiunitedwebsoft
 

Semelhante a How can I see with all that code in my view (20)

Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Decoupled drupal
Decoupled drupal Decoupled drupal
Decoupled drupal
 
Basics of XML
Basics of XMLBasics of XML
Basics of XML
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
XML-Javascript
XML-JavascriptXML-Javascript
XML-Javascript
 
XML-Javascript
XML-JavascriptXML-Javascript
XML-Javascript
 
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCRDrupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal introEdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
 
Introduction into Drupal site building
Introduction into Drupal site buildingIntroduction into Drupal site building
Introduction into Drupal site building
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010
 
Decoupled drupal DcRuhr
Decoupled drupal DcRuhrDecoupled drupal DcRuhr
Decoupled drupal DcRuhr
 
Making The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To SwallowMaking The Drupal Pill Easier To Swallow
Making The Drupal Pill Easier To Swallow
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate module
 
Drupal
DrupalDrupal
Drupal
 
Drupal module development training delhi
Drupal module development training delhiDrupal module development training delhi
Drupal module development training delhi
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

How can I see with all that code in my view

  • 1. RuHL How can I see with all that code in my view? Wednesday, December 9, 2009
  • 2. The first thought... Haml is so far away from HTML, why not take it further? Repeat content instead of having to write loops. %ul - @school.special_features.each do |feature| %li= feature.name # Maybe something like... %ul { repeat: special_features } %li= feature.name Wednesday, December 9, 2009
  • 3. The next minute... I could actually pull this off with HTML. <ul ruby=”_collection: special_features”> <li ruby=”name”/> </ul> # Which later changed to <ul> <li data-ruhl =”_collection: special_features, name”/> </ul> ...more on this coming up Wednesday, December 9, 2009
  • 4. Thoughts from JSP days and beyond • Working with designers inefficient after converting views. • Why convert the code from HTML to a language that generates HTML if it is not necessary? • Views didn’t garner the same architecture attention ‘code’ did. • Did formulating the Fat Model/Skinny Controller idea take everyone’s energy? • Over time, code in views grew as quick fixes were applied. • Little restrictions on what is allowed encourages misuse. • Testing views more difficult than models or controllers. • Shouldn’t the multiple attempts to improve view testing be an indicator? Wednesday, December 9, 2009
  • 5. The 2 minute RuHL history. • The attribute was initially called ruby. • Peter Cooper suggested data-ruby for HTML5 compliance. • Coworker suggested data-ruhl to prevent potential naming collisions. • Crystallized the idea of ‘No code in views’ • This became the rule that could not be broken. • Should not have to code extra HTML tags to make something work. • Exceptions to this arose and _swap was introduced. (details later) • Functionality to be driven by real use cases, not imagined scenarios. Wednesday, December 9, 2009
  • 6. Standalone RuHL RuHL can be used outside Sinatra and Rails. Ruhl::Engine.new(File.read(ʻhello_world.ruhlʼ)).render(self) Breaking it down: data = File.read(ʻhello_world.ruhlʼ) # read the html file engine = Ruhl::Engine.new(data) # instantiate the engine html = engine.render(self) # render the html # using self for context In the Rails helper, self is the @template object available to the controller. This gives you access to all the helpers available within the view. Wednesday, December 9, 2009
  • 7. RuHL: _if How would I conditionally display data? #Don’t show the div or it’s contents if there aren’t users. <div data-ruhl="_if: users?"> <table> <thead> <tr> <td>First Name</td> <td>Last Name</td> <td>Email</td> </tr> </thead> <tr data-ruhl="_collection: user_list"> <td data-ruhl="first_name">Andrew</td> <td data-ruhl="last_name">Stone</td> <td data-ruhl="email">andy@stonean.com</td> </tr> </table> </div> Wednesday, December 9, 2009
  • 8. RuHL: _unless How would I conditionally display data? #Show the message if there aren’t users. <p data-ruhl="_unless: users?">No Users were found.</p> If users, the <p> tag would not be included on output. Wednesday, December 9, 2009
  • 9. RuHL: _use I want to use the user object as the local object within the scope of the div to simplify the calls. The methods will first be tried against the local object, then the global context. <div data-ruhl="_use: current_user"> <h1> Editing <span data-ruhl="_swap: full_name"/></h1> <table> <thead> <tr> <td>First Name</td> <td>Last Name</td> <td>Email</td> </tr> </thead> <tr> <td data-ruhl="first_name">Andrew</td> <td data-ruhl="last_name">Stone</td> <td data-ruhl="email">andy@stonean.com</td> </tr> </table> </div> Wednesday, December 9, 2009
  • 10. RuHL: _use So what about iterating over a collection? <select id="states"> <option data-ruhl="_use: state_options"> </select> The option tag will be repeated for each item returned. state_options can return an array of hashes: def state_options [ {:value => 'AL', :inner_html => 'Alabama'}, {:value => 'AK', :inner_html => 'Alaska'}, {:value => 'AZ', :inner_html => 'Arizona'}, ... ] end :inner_html will set the contents of the tag. all other keys are treated as attributes for the tag. Wednesday, December 9, 2009
  • 11. RuHL: _swap I have some template text, but want to replace content within a paragraph. #Replace the span tag with the results of language <p>The programming language, <span data-ruhl='_swap:language'/>, is awesome.</p> Wednesday, December 9, 2009
  • 12. RuHL: partials, layouts and params <div id="page"> <div data-ruhl="_partial:file|header_search"/> <div data-ruhl="_render_" class="metro"/> <div data-ruhl="_partial:file|footer"/> </div> Can pass parameters to methods with a pipe (‘|’). Use _render_ to get the =yield result in Rails. Defining the layout works as expected within Rails. Outside of Rails, you pass a :layout option to the engine constructor. The value of the :layout option is the path to the file. Use :layout_source if you’ve cached the reading of the file (as Rails does). Use _partial to pull in page partials. The method, in this case :file, must return a path to the partial. Wednesday, December 9, 2009
  • 13. More information on keywords: http://stonean.com/page/ruhl Moving on. A lot to cover... Wednesday, December 9, 2009
  • 14. If the code isn’t in the view, where does it go? • RuHL encourages the use of the presenter pattern. • It’s easy with the helpers if you follow the convention in a Rails app: • Have presenter in app/presenters • Name presenter similar to controller conventions (just singular): class UserPresenter < Ruhl::Rails::Presenter end (file name: user_presenter.rb) Wednesday, December 9, 2009
  • 15. What does my controller look like? Controller methods look like: def new @post = Post.new present end def create @post = Post.new(params[:post]) if @post.save flash[:notice] = 'Post was successfully created.' redirect_to(@post) else present :new end end Wednesday, December 9, 2009
  • 16. And this works how? For this example, let’s say we are working in the UsersController. • Calling present in the controller method creates a new instance of the UserPresenter. • The UserPresenter instance is passed to the view as a local object. • RuHL will first apply all methods to the local object. If the local object does not respond to the method, RuHL then tries to apply the method to the context. • The context is everything you are accustomed to in a Rails view: • Controller methods exposed with helper_method • Helper methods (ApplicationHelper, UsersHelper) Wednesday, December 9, 2009
  • 17. And my model? For this example, let’s say we are working with the UserPresenter. • When the presenter is created, it has a local object called presentee which holds the instance of the model you are presenting. (@user) • If you have this call in your view: data-ruhl=”first_name” the order is: 1. Does the presenter respond_to?(:first_name) 1. Does the presenter have first_name defined? 2.Does the presentee (@user) have first_name defined? 2.Try the method against the context 1. Raises exception if method not found. Wednesday, December 9, 2009
  • 18. So what about testing? • With RuHL, rendering your view is not required to test. • Only interested in the correct placement and content of data-ruhl attributes. • Helper provided: <div class="single_box"> <h2>Topic: <span data-ruhl="_swap: name"/></h2> <div id="chart"> <img data-ruhl="src: chart_period"/> </div> </div> # To test above: it "calls to replace name" do data_ruhl('div.single_box > h2 > span').should == "_swap: name" end Wednesday, December 9, 2009
  • 19. But wait, there’s more... Since RuHL encourages presenters, test your presenters as you would your models. This simplifies your testing! • Don’t have to go through your controller to trigger conditions that decide the output in your view. • This decreases the amount of time required to run your tests. Wednesday, December 9, 2009
  • 20. Summary • Allowing code in your view is a bad practice. • This simple requirement ensures a holistic approach. • Utilize the presenter pattern to hold the code you would otherwise have placed in your view. • Using RuHL encourages continued designer involvement with the maintenance of views. Wednesday, December 9, 2009