Skip to content

Instantly share code, notes, and snippets.

@inossidabile
Created May 25, 2012 04:33
Show Gist options
  • Save inossidabile/2785784 to your computer and use it in GitHub Desktop.
Save inossidabile/2785784 to your computer and use it in GitHub Desktop.
Joosy / Blog / Layouts, Pages and Routing
# pages/posts/index.js.coffee
Joosy.namespace 'Posts', ->
class @IndexPage extends ApplicationPage
@layout ApplicationLayout
@view 'index'
@fetch (complete) ->
Post.find 'all', (posts) =>
@data.posts = posts
complete()
# pages/posts/show.js.coffee
Joosy.namespace 'Posts', ->
class @ShowPage extends ApplicationPage
@layout ApplicationLayout
@view 'show'
@fetch (complete) ->
Post.find @params.id, (post) =>
@data.post = post
complete()
rails g joosy:page blog/posts/index
# create blog/pages/posts
# create blog/pages/posts/index.js.coffee
# create blog/templates/pages/posts
# create blog/templates/pages/posts/index.jst.hamlc
rails g joosy:page blog/posts/show
# exist blog/pages/posts
# create blog/pages/posts/show.js.coffee
# exist blog/templates/pages/posts
# create blog/templates/pages/posts/show.jst.hamlc
-# templates/layouts/application.jst.hamlc
.navbar.navbar-fixed-top
.navbar-inner
.container
%a.brand{:href => '#!/'}
Joosy Blog
%ul.nav
%li.divider-vertical
%li
%a{:href => '#!/posts/new'} Write something
.container{:id => @yield()}
-# templates/pages/posts/index.jst.hamlc
.well
%h1
%i.icon-book
Blog post title
%sup.badge.badge-success
24.05.2012
%hr
%p
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent enim sem, consectetur ac sagittis malesuada, mattis eget tellus. Quisque malesuada tristique ipsum, et dignissim dolor porttitor eu. Integer luctus eros eu lectus condimentum viverra...
%a.btn.btn-info.btn-mini{:href => "#!/posts/1"}
Read it!
-# templates/pages/posts/show.jst.hamlc
%h1
%i.icon-book
Blog post title
%sup.badge.badge-success
24.05.2012
%hr
%p
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent enim sem, consectetur ac sagittis malesuada, mattis eget tellus. Quisque malesuada tristique ipsum, et dignissim dolor porttitor eu. Integer luctus eros eu lectus condimentum viverra. Maecenas vitae rhoncus urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur ac sapien eros.
-# templates/pages/posts/index.jst.hamlc
- @posts.each (post) =>
.well
%h1
%i.icon-book
= post('title')
%sup.badge.badge-success
24.05.2012
%hr
%p
= post('body').truncate(20)
%a.btn.btn-info.btn-mini{:href => "#!/posts/#{post.id()}"}
Read it!
-# templates/pages/posts/show.jst.hamlc
%h1
%i.icon-book
= @post('title')
%sup.badge.badge-success
24.05.2012
%hr
%p
= @post('body')
Joosy.Router.map
404 : (path) -> alert "Page '#{path}' was not found :("
'/' : -> @navigate '/posts'
'/posts' :
'/' : Posts.IndexPage
'/:id' : Posts.ShowPage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment