cells-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +1 -1
- data/lib/cell/helper/asset_helper.rb +54 -0
- data/lib/cell/rails.rb +110 -0
- data/lib/cell/railtie.rb +78 -0
- data/lib/cells/rails.rb +1 -6
- data/lib/cells/rails/version.rb +1 -1
- data/lib/rails/generators/cell/cell_generator.rb +43 -0
- data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
- data/lib/rails/generators/cell/templates/view.erb +7 -0
- data/lib/rails/generators/cell/templates/view.haml +4 -0
- data/lib/rails/generators/cell/templates/view.slim +2 -0
- data/lib/rails/generators/concept/concept_generator.rb +38 -0
- data/lib/rails/generators/concept/templates/concept.rb.erb +7 -0
- data/lib/rails/generators/concept/templates/view.erb +7 -0
- data/lib/rails/generators/concept/templates/view.haml +4 -0
- data/lib/rails/generators/concept/templates/view.slim +2 -0
- data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
- data/lib/rails/generators/test_unit/cell/templates/unit_test.rb.erb +11 -0
- data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4702ce8ee285649f10ba8b66f422ef18de70de17
|
4
|
+
data.tar.gz: 4cf37c137a196505c9ce67e309bcd3667a2b20a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4607ac2a54c333168cd171470fe8c672421e78b3221a7c597b7380af86ee63ec7e0b854c43549451eb2d3a4cf0790ed6fce8c162e2b81666d4ed7dafb87dc7d5
|
7
|
+
data.tar.gz: e3e3d5d3ec884b042d9841cffe05f2e544336d898ce5aad826be10783747c42219b0bbce13fa51ea02d3711b3720933d8d99679112e94b2c37de5574f8705a0f
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Cell
|
2
|
+
module Helper
|
3
|
+
# Delegate all asset-related helpers to the global helpers instance.
|
4
|
+
# This is the cleanest solution to leverage Rails' asset management and
|
5
|
+
# doesn't pollute your cell with weird asset modules from Rails.
|
6
|
+
module AssetHelper
|
7
|
+
# Extend if we forgot anything.
|
8
|
+
# This delegates asset helpers to the global Rails helper instance.
|
9
|
+
|
10
|
+
# http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html
|
11
|
+
%w{
|
12
|
+
javascript_include_tag
|
13
|
+
stylesheet_link_tag
|
14
|
+
|
15
|
+
asset_path
|
16
|
+
asset_url
|
17
|
+
image_tag
|
18
|
+
audio_path
|
19
|
+
audio_url
|
20
|
+
compute_asset_extname
|
21
|
+
compute_asset_host
|
22
|
+
compute_asset_path
|
23
|
+
font_path
|
24
|
+
font_url
|
25
|
+
image_path
|
26
|
+
image_url
|
27
|
+
javascript_path
|
28
|
+
javascript_url
|
29
|
+
path_to_asset
|
30
|
+
path_to_audio
|
31
|
+
path_to_font
|
32
|
+
path_to_image
|
33
|
+
path_to_javascript
|
34
|
+
path_to_stylesheet
|
35
|
+
path_to_video
|
36
|
+
stylesheet_path
|
37
|
+
stylesheet_url
|
38
|
+
url_to_asset
|
39
|
+
url_to_audio
|
40
|
+
url_to_font
|
41
|
+
url_to_image
|
42
|
+
url_to_javascript
|
43
|
+
url_to_stylesheet
|
44
|
+
url_to_video
|
45
|
+
video_path
|
46
|
+
video_url
|
47
|
+
}.each do |method|
|
48
|
+
define_method(method) do |*args|
|
49
|
+
::ActionController::Base.helpers.send(method, *args)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end # AssetHelper
|
53
|
+
end
|
54
|
+
end
|
data/lib/cell/rails.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
module Cell
|
2
|
+
def self.rails_version
|
3
|
+
Gem::Version.new(ActionPack::VERSION::STRING)
|
4
|
+
end
|
5
|
+
|
6
|
+
# These methods are automatically added to all controllers and views.
|
7
|
+
module RailsExtensions
|
8
|
+
module ActionController
|
9
|
+
def cell(name, model=nil, options={}, constant=::Cell::ViewModel, &block)
|
10
|
+
options[:context] ||= {}
|
11
|
+
options[:context][:controller] = self
|
12
|
+
|
13
|
+
constant.cell(name, model, options, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def concept(name, model=nil, options={}, &block)
|
17
|
+
cell(name, model, options, ::Cell::Concept, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ActionView
|
22
|
+
# Returns the cell instance for +name+. You may pass arbitrary options to your
|
23
|
+
# cell.
|
24
|
+
#
|
25
|
+
# = cell(:song, title: "Creeping Out Sara").(:show)
|
26
|
+
def cell(name, *args, &block)
|
27
|
+
controller.cell(name, *args, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# # See Cells::Rails::ActionController#render_cell.
|
31
|
+
# def render_cell(name, state, *args, &block)
|
32
|
+
# ::Cell::Rails.render_cell(name, state, controller, *args, &block)
|
33
|
+
# end
|
34
|
+
|
35
|
+
def concept(name, *args, &block)
|
36
|
+
controller.concept(name, *args, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gets included into Cell::ViewModel in a Rails environment.
|
41
|
+
module ViewModel
|
42
|
+
extend ActiveSupport::Concern
|
43
|
+
|
44
|
+
# DISCUSS: who actually uses forgery protection with cells? it is not working since 4, anyway?
|
45
|
+
# include ActionController::RequestForgeryProtection
|
46
|
+
included do
|
47
|
+
extend Uber::Delegates
|
48
|
+
delegates :parent_controller, :session, :params, :request, :config, :env, :url_options
|
49
|
+
# forgery protection.
|
50
|
+
delegates :parent_controller, :protect_against_forgery?, :form_authenticity_token, :request_forgery_protection_token
|
51
|
+
end
|
52
|
+
|
53
|
+
def call(*)
|
54
|
+
super.html_safe
|
55
|
+
end
|
56
|
+
|
57
|
+
def parent_controller
|
58
|
+
context[:controller]
|
59
|
+
end
|
60
|
+
alias_method :controller, :parent_controller
|
61
|
+
|
62
|
+
def perform_caching?
|
63
|
+
::ActionController::Base.perform_caching
|
64
|
+
end
|
65
|
+
|
66
|
+
def cache_store # we want to use DI to set a cache store in cell/rails.
|
67
|
+
::ActionController::Base.cache_store
|
68
|
+
end
|
69
|
+
|
70
|
+
module ClassMethods
|
71
|
+
def expand_cache_key(key)
|
72
|
+
::ActiveSupport::Cache.expand_cache_key(key, :cells)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# In Rails, there are about 10 different implementations of #url_for. Rails doesn't like the idea of objects, so they
|
78
|
+
# have helpers in modules. Those module are now included sequentially into other modules and/or classes. While they
|
79
|
+
# get included, they might or might not include methods, depending on the including module/class
|
80
|
+
# (example here: https://github.com/rails/rails/blob/cad20f720c4c6e04584253cd0a23f22b3d43ab0f/actionpack/lib/action_dispatch/routing/url_for.rb#L87).
|
81
|
+
#
|
82
|
+
# The outcome is that several module override #url_for, and if you're lucky, this works. If you're not, then #url_for breaks
|
83
|
+
# due to a raise in one of its basic implementations, introduced in 3.x, fixed in 4.0 and then re-introduced in 4.2
|
84
|
+
#
|
85
|
+
# This is extremely frustrating as no one in Rails core seems to tackle this problem and introduces a url object instead
|
86
|
+
# of this module madness. I have to constantly test and fix it in Cells. With the module below, I'll stop doing this.
|
87
|
+
#
|
88
|
+
# Either Rails works with Cells and we fix this in form of a URL object that gets passed into the cell (I'm happy with
|
89
|
+
# a global object here, too! Wow!) or URL helpers will stop working in Cells and a lot of people will be unhappy.
|
90
|
+
#
|
91
|
+
# Anyway, this is the reason we need this patch module. If you have trouble with URLs in Cells, then please ask Rails to
|
92
|
+
# fix their implementation. Thank you.
|
93
|
+
module HelpersAreShit
|
94
|
+
def url_for(options = nil) # from ActionDispatch:R:UrlFor.
|
95
|
+
case options
|
96
|
+
when nil
|
97
|
+
_routes.url_for(url_options.symbolize_keys)
|
98
|
+
when Hash
|
99
|
+
_routes.url_for(options.symbolize_keys.reverse_merge!(url_options))
|
100
|
+
when String
|
101
|
+
options
|
102
|
+
when Array
|
103
|
+
polymorphic_url(options, options.extract_options!)
|
104
|
+
else
|
105
|
+
polymorphic_url(options)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/cell/railtie.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
require "cell/rails"
|
3
|
+
|
4
|
+
module Cell
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
|
7
|
+
config.cells = ActiveSupport::OrderedOptions.new
|
8
|
+
|
9
|
+
initializer("cells.attach_router") do |app|
|
10
|
+
ViewModel.class_eval do
|
11
|
+
include app.routes.url_helpers # TODO: i hate this, make it better in Rails.
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# ruthlessly stolen from the zurb-foundation gem.
|
16
|
+
initializer "cells.update_asset_paths" do |app|
|
17
|
+
Array(app.config.cells.with_assets).each do |cell_class|
|
18
|
+
# puts "@@@@@ #{cell_class.camelize.constantize.prefixes}"
|
19
|
+
app.config.assets.paths += cell_class.camelize.constantize.prefixes # Song::Cell.prefixes
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
initializer "cells.rails_extensions" do |app|
|
24
|
+
ActiveSupport.on_load(:action_controller) do
|
25
|
+
self.class_eval do
|
26
|
+
include ::Cell::RailsExtensions::ActionController
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveSupport.on_load(:action_view) do
|
31
|
+
self.class_eval do
|
32
|
+
include ::Cell::RailsExtensions::ActionView
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require "cell/rails/collection"
|
37
|
+
require "cell/rails/constant_for"
|
38
|
+
|
39
|
+
Cell::Collection.send :include, Cell::RailsExtension::Collection
|
40
|
+
Cell::ViewModel.send :include, Cell::RailsExtension::ConstantFor
|
41
|
+
end
|
42
|
+
|
43
|
+
initializer "cells.include_default_helpers" do
|
44
|
+
# include asset helpers (image_path, font_path, ect)
|
45
|
+
ViewModel.class_eval do
|
46
|
+
include ActionView::Helpers::FormHelper # includes ActionView::Helpers::UrlHelper, ActionView::Helpers::FormTagHelper
|
47
|
+
include ::Cell::RailsExtensions::HelpersAreShit
|
48
|
+
|
49
|
+
require "cell/helper/asset_helper"
|
50
|
+
include Cell::Helper::AssetHelper
|
51
|
+
|
52
|
+
# set VM#cache_store, etc.
|
53
|
+
include RailsExtensions::ViewModel
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO: allow to turn off this.
|
58
|
+
initializer "cells.include_template_module", after: "cells.include_default_helpers" do
|
59
|
+
# yepp, this is happening. saves me a lot of coding in each extension.
|
60
|
+
ViewModel.send(:include, Cell::Erb) if Cell.const_defined?(:Erb, false)
|
61
|
+
ViewModel.send(:include, Cell::Haml) if Cell.const_defined?(:Haml, false)
|
62
|
+
ViewModel.send(:include, Cell::Hamlit) if Cell.const_defined?(:Hamlit, false)
|
63
|
+
ViewModel.send(:include, Cell::Slim) if Cell.const_defined?(:Slim, false)
|
64
|
+
end
|
65
|
+
# ViewModel.template_engine = app.config.app_generators.rails.fetch(:template_engine, "erb").to_s
|
66
|
+
|
67
|
+
initializer("cells.development") do |app|
|
68
|
+
if Rails.env == "development"
|
69
|
+
require "cell/development"
|
70
|
+
ViewModel.send(:include, Development)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
rake_tasks do
|
75
|
+
load "tasks/cells.rake"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/cells/rails.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
require "cells/rails/version"
|
2
2
|
require "cells"
|
3
3
|
|
4
|
-
require "cell/rails/collection"
|
5
|
-
require "cell/rails/constant_for"
|
6
|
-
|
7
|
-
Cell::Collection.send :include, Cell::RailsExtension::Collection
|
8
|
-
Cell::ViewModel.send :include, Cell::RailsExtension::ConstantFor
|
9
|
-
|
10
4
|
require "cell/caching/notification"
|
5
|
+
require "cell/rails"
|
11
6
|
require "cell/railtie"
|
12
7
|
|
13
8
|
module Cell
|
data/lib/cells/rails/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class CellGenerator < NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
class_option :parent, type: :string, desc: 'The parent class for the generated cell'
|
7
|
+
class_option :e, type: :string, desc: 'The template engine'
|
8
|
+
|
9
|
+
check_class_collision suffix: 'Cell'
|
10
|
+
|
11
|
+
argument :actions, type: :array, default: [], banner: 'action action2'
|
12
|
+
|
13
|
+
def create_cell_file
|
14
|
+
template 'cell.rb.erb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_view_files
|
18
|
+
states.each do |state|
|
19
|
+
@state = state
|
20
|
+
@path = File.join('app/cells', class_path, file_name, "#{state}.#{template_engine}")
|
21
|
+
template "view.#{template_engine}", @path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
hook_for :test_framework
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parent_class_name
|
30
|
+
options[:parent] || 'Cell::ViewModel'
|
31
|
+
end
|
32
|
+
|
33
|
+
# The show state is included by default
|
34
|
+
def states
|
35
|
+
(['show'] + actions).uniq
|
36
|
+
end
|
37
|
+
|
38
|
+
def template_engine
|
39
|
+
(options[:e] || Rails.application.config.app_generators.rails[:template_engine] || 'erb').to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class ConceptGenerator < NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
class_option :e, type: :string, desc: 'The template engine'
|
7
|
+
argument :actions, type: :array, default: [], banner: 'action action2'
|
8
|
+
|
9
|
+
check_class_collision suffix: 'Concept'
|
10
|
+
|
11
|
+
|
12
|
+
def create_concept
|
13
|
+
template 'concept.rb.erb', File.join('app/concepts', class_path, file_name, 'cell.rb')
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_views
|
17
|
+
states.each do |state|
|
18
|
+
@state = state
|
19
|
+
@path = File.join('app/concepts', class_path, file_name, 'views', "#{state}.#{template_engine}")
|
20
|
+
template "view.#{template_engine}", @path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
hook_for :test_framework
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def template_engine
|
29
|
+
(options[:e] || Rails.application.config.app_generators.rails[:template_engine] || 'erb').to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
# The show state is included by default
|
33
|
+
def states
|
34
|
+
(['show'] + actions).uniq
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators/test_unit'
|
2
|
+
|
3
|
+
module TestUnit # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class CellGenerator < Base # :nodoc:
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :actions, type: :array, default: []
|
8
|
+
check_class_collision suffix: 'CellTest'
|
9
|
+
|
10
|
+
def create_test_file
|
11
|
+
template 'unit_test.rb.erb', File.join('test/cells', class_path, "#{file_name}_cell_test.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def states
|
17
|
+
(['show'] + actions).uniq
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators/test_unit'
|
2
|
+
|
3
|
+
module TestUnit # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class ConceptGenerator < Base # :nodoc:
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :actions, type: :array, default: []
|
8
|
+
check_class_collision suffix: 'ConceptTest'
|
9
|
+
|
10
|
+
def create_test_file
|
11
|
+
template 'unit_test.rb.erb', File.join('test/concepts', class_path, file_name, 'cell_test.rb')
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def states
|
17
|
+
(['show'] + actions).uniq
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -123,12 +123,29 @@ files:
|
|
123
123
|
- Rakefile
|
124
124
|
- cells-rails.gemspec
|
125
125
|
- lib/cell/caching/notification.rb
|
126
|
+
- lib/cell/helper/asset_helper.rb
|
127
|
+
- lib/cell/rails.rb
|
126
128
|
- lib/cell/rails/collection.rb
|
127
129
|
- lib/cell/rails/constant_for.rb
|
130
|
+
- lib/cell/railtie.rb
|
128
131
|
- lib/cell/test_case.rb
|
129
132
|
- lib/cell/translation.rb
|
130
133
|
- lib/cells/rails.rb
|
131
134
|
- lib/cells/rails/version.rb
|
135
|
+
- lib/rails/generators/cell/cell_generator.rb
|
136
|
+
- lib/rails/generators/cell/templates/cell.rb.erb
|
137
|
+
- lib/rails/generators/cell/templates/view.erb
|
138
|
+
- lib/rails/generators/cell/templates/view.haml
|
139
|
+
- lib/rails/generators/cell/templates/view.slim
|
140
|
+
- lib/rails/generators/concept/concept_generator.rb
|
141
|
+
- lib/rails/generators/concept/templates/concept.rb.erb
|
142
|
+
- lib/rails/generators/concept/templates/view.erb
|
143
|
+
- lib/rails/generators/concept/templates/view.haml
|
144
|
+
- lib/rails/generators/concept/templates/view.slim
|
145
|
+
- lib/rails/generators/test_unit/cell/cell_generator.rb
|
146
|
+
- lib/rails/generators/test_unit/cell/templates/unit_test.rb.erb
|
147
|
+
- lib/rails/generators/test_unit/concept/concept_generator.rb
|
148
|
+
- lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb
|
132
149
|
homepage: http://trailblazer.to
|
133
150
|
licenses: []
|
134
151
|
metadata: {}
|