GithubHelp home page GithubHelp logo

yogeshjain999 / trailblazer-cells Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trailblazer/trailblazer-cells

0.0 1.0 0.0 25 KB

Trailblazer's file structure for Cells.

License: Other

Ruby 99.15% HTML 0.85%

trailblazer-cells's Introduction

Trailblazer::Cells

Trailblazer's file layout for Cells.

View Prefixes

In Trailblazer, class structures such as the following are very common, let's say for a post concept, here are the class headers, and where the view directory gets resolved to.

module Post
  module Cell
    class New < Trailblazer::Cell         # => app/concepts/post/view
    class Show < Trailblazer::Cell        # => app/concepts/post/view
      class SideBar < Trailblazer::Cell   # => app/concepts/post/view

Automatic show

You don't have to define a show method, Trailblazer::Cell will have one that looks as follows.

class Trailblazer::Cell
  def show
    render
  end

View Name

When calling render, the view name is inferred from the class name.

module Post
  module Cell
    class New < Trailblazer::Cell         # => new.erb
    class Show < Trailblazer::Cell        # => show.erb
      class SideBar < Trailblazer::Cell   # => side_bar.erb

You can still override using render view: :name.

Layout

You can pass a layout cell into every Trailblazer::Cell which will render the layout.

Post::Cell::Show.new(post, layout: Gemgem::Cell::Layout).()

The :layout option has to refer to a cell class. When invoked, the layout cell will receive the content of the actual cell under :content, resulting in a call as follows.

Gemgem::Cell::Layout.new(post,
  content: Post::Cell::Show.new(post)
)

The layout cell's show view can sit in any directory, for example gemgem/view/layout.rb.

<html>
Yay, I'm the layout!

<%= content %>
</html>

It's up to you what you do with the :content option. Here's the Trailblazer way.

class Gemgem::Cell::Layout < Trailblazer::Cell
  self.view_paths = ["gemgem"]
  def content
    @options[:content]
  end
end

Cells with layout cells allow replacing a frameworks entire view stack, e.g. ActionView.

Namespaces

It works identical with namespaces.

View Paths

Some projects do not use the app/concept view path. This can be changed as follows.

Trailblazer::Cell.view_paths = ["concepts"]

Note that this will change for all cells, including bundled in gems. Introduce an Application::Cell if you don't like that.

Dependencies

This gem has only one dependency: cells. Note that it does not need trailblazer.

trailblazer-cells's People

Contributors

apotonick avatar seuros avatar rickenharp avatar emaglio avatar george-carlin avatar olleolleolle avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.