0.0
No release in over 3 years
An attempt at writing a very simple cells gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 4.0.0
 Project Readme

SimpleCells

Install

Add to your Gemfile and bundle:

gem "simple_cells"

Add the render method by including the helper in your ApplicationHelper:

module ApplicationHelper
  include SimpleCells::ViewsHelper
end

Autoload the simple cells through "application.rb":

config.autoload_paths << Rails.root.join("app", "simple_cells")

Usage

Add a cells-class to your application in "app/simple_cells/users_simple_cell.rb":

class UsersSimpleCell < SimpleCells::BaseCell
  def my_action
  end

  def helper_method
    "Hello from helper method"
  end
end

Then add a view file for the action in "app/views/simple_cells/users/my_action.html.erb":

Hello world
Content of my variable: <%= simple_cell[:my_variable] %>
Helper method: <%= simple_cell.helper_method %>

You can now render it like this from another ERB file:

<%= render_simple_cell :users, :my_action, my_variable: "Test" %>

Check if a variable has been given:

class MyCell < SimpleCells::BaseCell
  def my_method
    if simple_cell_argument?
      puts "Variable has been given"
    else
      puts "Variable has not been given"
    end
  end
end

Testing

You can test your cells individually like this:

require "rails_helper"

describe "my cell" do
  it "renders" do
    helper = SimpleCells::SpecHelper.new("users/something", :show)
    expect(helper.body).to include "some text"
  end
end

License

This project rocks and uses MIT-LICENSE.