Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance #510

Merged
merged 13 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI
on: [push, pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, head]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: bundle exec rake
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
source "https://rubygems.org"

gem "minitest", "~> 5.2"
gem "cells-erb"#, path: "../cells-erb"
gem "benchmark-ips"
gem "minitest-line"

gemspec

# gem "uber", path: "../uber"
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

*View Components for Ruby and Rails.*

[![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)
[![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
[![Build
Status](https://travis-ci.org/apotonick/cells.svg)](https://travis-ci.org/apotonick/cells)
[![Zulip Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://trailblazer.zulipchat.com/login/)
[![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](https://trailblazer.to/2.1/#callout-section)
![Build
Status](https://github.com/trailblazer/cells/actions/workflows/ci.yml/badge.svg
)
[![Gem Version](https://badge.fury.io/rb/cells.svg)](http://badge.fury.io/rb/cells)

## Overview

Cells allow you to encapsulate parts of your UI into components into _view models_. View models, or cells, are simple ruby classes that can render templates.

Nevertheless, a cell gives you more than just a template renderer. They allow proper OOP, polymorphic builders, [nesting](#nested-cells), view inheritance, using Rails helpers, [asset packaging](http://trailblazer.to/gems/cells/rails.html#asset-pipeline) to bundle JS, CSS or images, simple distribution via gems or Rails engines, encapsulated testing, [caching](#caching), and [integrate with Trailblazer](https://github.com/trailblazer/trailblazer-cells).
Nevertheless, a cell gives you more than just a template renderer. They allow proper OOP, polymorphic builders, [nesting](#nested-cells), view inheritance, using Rails helpers, [asset packaging](https://trailblazer.to/2.1/docs/cells.html#cells-rails-asset-pipeline) to bundle JS, CSS or images, simple distribution via gems or Rails engines, encapsulated testing, [caching](#caching), and [integrate with Trailblazer](https://github.com/trailblazer/trailblazer-cells).

## Full Documentation

Cells is part of the Trailblazer framework. [Full documentation](http://trailblazer.to/gems/cells) is available on the project site.
Cells is part of the Trailblazer framework. [Full documentation](https://trailblazer.to/2.1/docs/cells/) is available on the project site.

Cells is completely decoupled from Rails. However, Rails-specific functionality is to be found [here](http://trailblazer.to/gems/cells/rails.html).
Cells is completely decoupled from Rails. However, Rails-specific functionality is to be found [here](https://trailblazer.to/2.1/docs/cells/#cells-4-rails).

## Rendering Cells

Expand Down Expand Up @@ -151,7 +152,7 @@ Capybara.string(html).must_have_css "h3"

It is completely up to you how you test, whether it's RSpec, MiniTest or whatever. All the cell does is return HTML.

[In Rails, there's support](http://trailblazer.to/gems/cells/testing.html) for TestUnit, MiniTest and RSpec available, along with Capybara integration.
[In Rails, there's support](https://trailblazer.to/2.1/docs/cells/#cells-4-overview-testing) for TestUnit, MiniTest and RSpec available, along with Capybara integration.

## Properties

Expand Down Expand Up @@ -182,7 +183,7 @@ song.title #=> "<script>Dangerous</script>"
Comment::Cell.(song).title #=> &lt;script&gt;Dangerous&lt;/script&gt;
```

Properties and escaping are [documented here](http://trailblazer.to/gems/cells/api.html#html-escaping).
Properties and escaping are [documented here](https://trailblazer.to/2.1/docs/cells/#cells-4-api-html-escaping).

## Installation

Expand Down Expand Up @@ -270,7 +271,7 @@ end

## Asset Packaging

Cells can easily ship with their own JavaScript, CSS and more and be part of Rails' asset pipeline. Bundling assets into a cell allows you to implement super encapsulated widgets that are stand-alone. Asset pipeline is [documented here](http://trailblazer.to/gems/cells/rails.html#asset-pipeline).
Cells can easily ship with their own JavaScript, CSS and more and be part of Rails' asset pipeline. Bundling assets into a cell allows you to implement super encapsulated widgets that are stand-alone. Asset pipeline is [documented here](https://trailblazer.to/2.1/docs/cells/#cells-4-rails-asset-pipeline).

## Render API

Expand Down Expand Up @@ -344,7 +345,7 @@ This works both in cell views and on the instance, in states.

## View Inheritance

You can not only inherit code across cell classes, but also views. This is extremely helpful if you want to override parts of your UI, only. It's [documented here](http://trailblazer.to/gems/cells/api.html#view-inheritance).
You can not only inherit code across cell classes, but also views. This is extremely helpful if you want to override parts of your UI, only. It's [documented here](https://trailblazer.to/2.1/docs/cells/#cells-4-api-view-inheritance).

## Collections

Expand All @@ -357,7 +358,7 @@ cell(:comment, collection: comments).()

This will invoke `cell(:comment, comment).()` three times and concatenate the rendered output automatically.

Learn more [about collections here](http://trailblazer.to/gems/cells/api.html#collection).
Learn more [about collections here](https://trailblazer.to/2.1/docs/cells/#cells-4-api-collection).


## Builder
Expand All @@ -382,7 +383,7 @@ The `#cell` helper takes care of instantiating the right cell class for you.
cell(:comment, Post.find(1)) #=> creates a PostCell.
```

Learn more [about builders here](http://trailblazer.to/gems/cells/api.html#builder).
Learn more [about builders here](https://trailblazer.to/2.1/docs/cells/#cells-4-api-builder).

## Caching

Expand All @@ -401,16 +402,14 @@ The `::cache` method will forward options to the caching engine.
cache :show, expires_in: 10.minutes
```

You can also compute your own cache key, use dynamic keys, cache tags, and conditionals using `:if`. Caching is documented [here](http://trailblazer.to/gems/cells/api.html#caching) and in chapter 8 of the [Trailblazer book](http://leanpub.com/trailblazer).
You can also compute your own cache key, use dynamic keys, cache tags, and conditionals using `:if`. Caching is documented [here](https://trailblazer.to/2.1/docs/cells/#cells-4-api-caching) and in chapter 8 of the [Trailblazer book](http://leanpub.com/trailblazer).


## The Book

Cells is part of the [Trailblazer project](https://github.com/apotonick/trailblazer). Please [buy my book](https://leanpub.com/trailblazer) to support the development and to learn all the cool stuff about Cells. The book discusses many use cases of Cells.

<a href="https://leanpub.com/trailblazer">
![](https://raw.githubusercontent.com/apotonick/trailblazer/master/doc/trb.jpg)
</a>
[![trb](https://raw.githubusercontent.com/apotonick/trailblazer/master/doc/trb.jpg)](https://leanpub.com/trailblazer)

* Basic view models, replacing helpers, and how to structure your view into cell components (chapter 2 and 4).
* Advanced Cells API (chapter 4 and 6).
Expand All @@ -422,11 +421,11 @@ The book picks up where the README leaves off. Go grab a copy and support us - i

## This is not Cells 3.x!

Temporary note: This is the README and API for Cells 4. Many things have improved. If you want to upgrade, [follow this guide](https://github.com/apotonick/cells/wiki/From-Cells-3-to-Cells-4---Upgrading-Guide). When in trouble, join the [Gitter channel](https://gitter.im/trailblazer/chat).
Temporary note: This is the README and API for Cells 4. Many things have improved. If you want to upgrade, [follow this guide](https://github.com/apotonick/cells/wiki/From-Cells-3-to-Cells-4---Upgrading-Guide). When in trouble, join the [Zulip channel](https://trailblazer.zulipchat.com/login/).

## LICENSE

Copyright (c) 2007-2015, Nick Sutterer
Copyright (c) 2007-2024, Nick Sutterer

Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers

Expand Down
14 changes: 0 additions & 14 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,5 @@ Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.pattern = 'test/*_test.rb'
test.verbose = true
# Ruby built-in warnings contain way too much noise to be useful. Consider turning them on again when the following issues are accepted in ruby:
# * https://bugs.ruby-lang.org/issues/10967 (remove warning: private attribute?)
# * https://bugs.ruby-lang.org/issues/12299 (customized warning handling)
test.warning = false
end

# Rake::TestTask.new(:rails) do |test|
# test.libs << 'test/rails'
# test.test_files = FileList['test/rails4.2/*_test.rb']
# test.verbose = true
# end

# rails_task = Rake::Task["rails"]
# test_task = Rake::Task["test"]
# default_task.enhance { test_task.invoke }
# default_task.enhance { rails_task.invoke }
37 changes: 0 additions & 37 deletions benchmarks/class_builder.rb

This file was deleted.

47 changes: 0 additions & 47 deletions benchmarks/collection.rb

This file was deleted.

52 changes: 30 additions & 22 deletions cells.gemspec
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
lib = File.expand_path("../lib/", __FILE__)
$:.unshift lib unless $:.include?(lib)

require "cell/version"
require_relative 'lib/cell/version'

Gem::Specification.new do |spec|
spec.name = "cells"
spec.name = 'cells'
spec.version = Cell::VERSION
spec.platform = Gem::Platform::RUBY
spec.authors = ["Nick Sutterer"]
spec.email = ["apotonick@gmail.com"]
spec.homepage = "https://github.com/apotonick/cells"
spec.summary = %q{View Models for Ruby and Rails.}
spec.description = %q{View Models for Ruby and Rails, replacing helpers and partials while giving you a clean view architecture with proper encapsulation.}
spec.license = "MIT"
spec.authors = ['Nick Sutterer']
spec.email = ['apotonick@gmail.com']
spec.homepage = 'https://github.com/trailblazer/cells'
spec.summary = 'View Models for Ruby and Rails.'
spec.description = 'View Models for Ruby and Rails, replacing helpers and partials while giving you a clean view architecture with proper encapsulation.'
spec.license = 'MIT'

spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/HEAD/CHANGES.md"
spec.metadata['documentation_uri'] = 'https://trailblazer.to/2.1/docs/cells'
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage
spec.metadata['wiki_uri'] = "#{spec.homepage}/wiki"

spec.files = `git ls-files`.split("\n")
spec.test_files = `git ls-files -- {test}/*`.split("\n")
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |file|
file.start_with?(*%w[.git Gemfile Rakefile TODO test])
end
end
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.5'

spec.add_dependency "uber", "< 0.2.0"
spec.add_dependency 'declarative-builder', '~> 0.2.0'
spec.add_dependency 'tilt', '>= 1.4', '< 3'
spec.add_dependency "declarative-option", "< 0.2.0"
spec.add_dependency "declarative-builder", "< 0.2.0"
spec.add_dependency "tilt", ">= 1.4", "< 3"
spec.add_dependency 'uber', '< 0.2.0'

spec.add_development_dependency "rake"
spec.add_development_dependency "capybara"
spec.add_development_dependency "cells-erb", ">= 0.0.4"
spec.add_development_dependency 'capybara'
spec.add_development_dependency 'cells-erb', '>= 0.1.0'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'debug'
end
3 changes: 1 addition & 2 deletions lib/cell/view_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def process_options!(options)

# Computes the view name from the call stack in which `render` was invoked.
def state_for_implicit_render(options)
_caller = RUBY_VERSION < "2.0" ? caller(3) : caller(3, 1) # TODO: remove case in 5.0 when dropping 1.9.
_caller[0].match(/`(\w+)/)[1]
caller(3, 1)[0].match(/`(\w+)|#(\w+)'/).captures.compact.first
end

include Layout
Expand Down
18 changes: 9 additions & 9 deletions test/builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class BuilderTest < MiniTest::Spec
class BuilderTest < Minitest::Spec
Song = Struct.new(:title)
Hit = Struct.new(:title)

Expand Down Expand Up @@ -36,28 +36,28 @@ class EvergreenCell < SongCell
end

# the original class is used when no builder matches.
it { SongCell.(Song.new("Nation States"), {}).must_be_instance_of SongCell }
it { assert_instance_of SongCell, SongCell.(Song.new("Nation States"), {}) }

it do
cell = SongCell.(Hit.new("New York"), {})
cell.must_be_instance_of HitCell
cell.options.must_equal({})
assert_instance_of HitCell, cell
assert_equal({}, cell.options)
end

it do
cell = SongCell.(Song.new("San Francisco"), evergreen: true)
cell.must_be_instance_of EvergreenCell
cell.options.must_equal({evergreen:true})
assert_instance_of EvergreenCell, cell
assert_equal({evergreen: true}, cell.options)
end

# without arguments.
it { SongCell.(Hit.new("Frenzy")).must_be_instance_of HitCell }
it { assert_instance_of HitCell, SongCell.(Hit.new("Frenzy")) }

# with collection.
it { SongCell.(collection: [Song.new("Nation States"), Hit.new("New York")]).().must_equal "* Nation States* **New York**" }
it { assert_equal "* Nation States* **New York**", SongCell.(collection: [Song.new("Nation States"), Hit.new("New York")]).() }

# with Concept
class Track < Cell::Concept
end
it { Track.().must_be_instance_of Track }
it { assert_instance_of Track, Track.() }
end
5 changes: 2 additions & 3 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class Index < Cell::ViewModel
end

it do
Index.new(1).().must_equal("1")
Index.new(2).().must_equal("1")
assert_equal "1", Index.new(1).()
assert_equal "1", Index.new(2).()
end
end

Loading