0
Alex Gaziev’sGEM GON@gazay (github, twitter)Saturday, June 8, 13
Saturday, June 8, 13
SURFINGJAZZOSS:russia => ‘BALI’Saturday, June 8, 13
Some of my worksgontalksgon-sinatratonikishockeypuck...Saturday, June 8, 13
A little about GONSend data from action to JSStarted 2 years ago~800 stars50+ forks and PRsSaturday, June 8, 13
Data to JS:data-attributeInstance variable in controllerData-attribute in viewFind tag and parse data attributeSaturday, J...
Data to JS:data-attr examplecontroller# home_controller.rbdef index# some logic@products = counted_products_collectionendS...
Data to JS:data-attr exampleview# views/home/index.html.erb... some content<%= contant_tag “div”, id: “products”, data:{ p...
Data to JS:data-attr exampleJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething $(‘#products’).data(‘products’...
Data to JS:javascript_tagExcess lines inside your viewsYou should think what you writeSaturday, June 8, 13
Data to JS:javascript_tagview# views/home/index.html.erb... some content<%= javascript_tag do %>window.prodsURL = “<%=j pr...
Data to JS:javascript_tagJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething prodsSaturday, June 8, 13
Saturday, June 8, 13
Data to JSGONViews step - once (perfect - in layout)Don’t have to think about escapingStored uniq data per requestSaturday...
Data to JS:GON examplecontroller# home_controller.rbdef index# some logicgon.products = counted_collectiongon.products_url...
Data to JS:GON exampleview# views/layouts/layout.html.erb<head><%= include_gon(options) %>... your js, css etcSaturday, Ju...
Data to JS:GON exampleJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething gon.productsSaturday, June 8, 13
Usual ways: consEscaping ( “</script><script>evil()</script>”)Excess lines in your viewsSearch for tag and parse attribute...
GON: prosAutomatically escape and transformto_json all dataWhat you write in action – you’ll get in JSShould modify views ...
GON. Next versionsGenerate json with template enginesShare data between requestsRenew data in JS gon easy waySaturday, Jun...
GONRABL and jBuilderSuccess!ScreencastRuby WeeklyMore users => more PRsSaturday, June 8, 13
GON, RABL andjBuilderwhy so cool?All power of RABL and jBuilderClean your controller new wayRender multiple templates with...
GON and RABLmulti templates# home_controller.rbdef indexgon.rabl ‘path_to_temlpate1’, as: ‘posts’gon.rabl ‘path_to_templat...
GON and jBuilderproblemsjBuilder rendering flowMetaprogrammingWhole environment for evalSaturday, June 8, 13
Saturday, June 8, 13
GON GlobalShare data application-wideInitial dataChange settings everywhere by eventSaturday, June 8, 13
GON Globalinit data example# config/initializers/gon.rbGon.global.pictures_per_user = 4# app/assets/javascripts/imageboard....
GON Globalchange data example# app/model/user.rbafter_save :change_users_limitdef change_users_limitif User.count > 1000Go...
GON watchRenew data for variableNo excess LOCUse current state of actionSaturday, June 8, 13
GON watch:how it works# home_controller.rbdef indexnum = User.count * factor + params[:some].to_igon.watch.pictures_per_re...
GON watch:how it works# layout.html.erb<head><%= include_gon(watch: true) %>...Saturday, June 8, 13
GON watch:how it works# home_index.js.coffeerenewLimit = (count) ->$(‘#limit-counter’).text(count)gon.watch(‘pictures_per_...
GON watchexampleSaturday, June 8, 13
Thank you!Any questions?http://github.com/gazay/gonSaturday, June 8, 13
Upcoming SlideShare
Loading in...5
×

Gon gem. For RDRC 2013, June 7

998

Published on

It's all about gon. gongongon

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
998
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Gon gem. For RDRC 2013, June 7"

  1. 1. Alex Gaziev’sGEM GON@gazay (github, twitter)Saturday, June 8, 13
  2. 2. Saturday, June 8, 13
  3. 3. SURFINGJAZZOSS:russia => ‘BALI’Saturday, June 8, 13
  4. 4. Some of my worksgontalksgon-sinatratonikishockeypuck...Saturday, June 8, 13
  5. 5. A little about GONSend data from action to JSStarted 2 years ago~800 stars50+ forks and PRsSaturday, June 8, 13
  6. 6. Data to JS:data-attributeInstance variable in controllerData-attribute in viewFind tag and parse data attributeSaturday, June 8, 13
  7. 7. Data to JS:data-attr examplecontroller# home_controller.rbdef index# some logic@products = counted_products_collectionendSaturday, June 8, 13
  8. 8. Data to JS:data-attr exampleview# views/home/index.html.erb... some content<%= contant_tag “div”, id: “products”, data:{ products: @products } do %>Loading products...<% end %>Saturday, June 8, 13
  9. 9. Data to JS:data-attr exampleJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething $(‘#products’).data(‘products’)Saturday, June 8, 13
  10. 10. Data to JS:javascript_tagExcess lines inside your viewsYou should think what you writeSaturday, June 8, 13
  11. 11. Data to JS:javascript_tagview# views/home/index.html.erb... some content<%= javascript_tag do %>window.prodsURL = “<%=j products_url %>”window.prods = <%=raw @prods.to_json %><% end %>Saturday, June 8, 13
  12. 12. Data to JS:javascript_tagJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething prodsSaturday, June 8, 13
  13. 13. Saturday, June 8, 13
  14. 14. Data to JSGONViews step - once (perfect - in layout)Don’t have to think about escapingStored uniq data per requestSaturday, June 8, 13
  15. 15. Data to JS:GON examplecontroller# home_controller.rbdef index# some logicgon.products = counted_collectiongon.products_url = products_urlendSaturday, June 8, 13
  16. 16. Data to JS:GON exampleview# views/layouts/layout.html.erb<head><%= include_gon(options) %>... your js, css etcSaturday, June 8, 13
  17. 17. Data to JS:GON exampleJS# assets/javascripts/pages/home.js.coffeejQuery ->doSomething gon.productsSaturday, June 8, 13
  18. 18. Usual ways: consEscaping ( “</script><script>evil()</script>”)Excess lines in your viewsSearch for tag and parse attributesViews stepSaturday, June 8, 13
  19. 19. GON: prosAutomatically escape and transformto_json all dataWhat you write in action – you’ll get in JSShould modify views onceSaturday, June 8, 13
  20. 20. GON. Next versionsGenerate json with template enginesShare data between requestsRenew data in JS gon easy waySaturday, June 8, 13
  21. 21. GONRABL and jBuilderSuccess!ScreencastRuby WeeklyMore users => more PRsSaturday, June 8, 13
  22. 22. GON, RABL andjBuilderwhy so cool?All power of RABL and jBuilderClean your controller new wayRender multiple templates with GONSaturday, June 8, 13
  23. 23. GON and RABLmulti templates# home_controller.rbdef indexgon.rabl ‘path_to_temlpate1’, as: ‘posts’gon.rabl ‘path_to_template2’, as: ‘users’gon.rabl ‘path_to_template3’, as: ‘admins’gon.rabl # app/views/home/index.rablendSaturday, June 8, 13
  24. 24. GON and jBuilderproblemsjBuilder rendering flowMetaprogrammingWhole environment for evalSaturday, June 8, 13
  25. 25. Saturday, June 8, 13
  26. 26. GON GlobalShare data application-wideInitial dataChange settings everywhere by eventSaturday, June 8, 13
  27. 27. GON Globalinit data example# config/initializers/gon.rbGon.global.pictures_per_user = 4# app/assets/javascripts/imageboard.js.coffeesetLimitToUser = gon.global.pictures_per_requestSaturday, June 8, 13
  28. 28. GON Globalchange data example# app/model/user.rbafter_save :change_users_limitdef change_users_limitif User.count > 1000Gon.global.pictures_per_request = 3endendSaturday, June 8, 13
  29. 29. GON watchRenew data for variableNo excess LOCUse current state of actionSaturday, June 8, 13
  30. 30. GON watch:how it works# home_controller.rbdef indexnum = User.count * factor + params[:some].to_igon.watch.pictures_per_request = numgon.watch.other_num = num * factor2endSaturday, June 8, 13
  31. 31. GON watch:how it works# layout.html.erb<head><%= include_gon(watch: true) %>...Saturday, June 8, 13
  32. 32. GON watch:how it works# home_index.js.coffeerenewLimit = (count) ->$(‘#limit-counter’).text(count)gon.watch(‘pictures_per_request’, interval: 1000,renewLimit)Saturday, June 8, 13
  33. 33. GON watchexampleSaturday, June 8, 13
  34. 34. Thank you!Any questions?http://github.com/gazay/gonSaturday, June 8, 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×