Skip to content

Commit

Permalink
Chanko no longer prepares view_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxa committed Oct 7, 2023
1 parent 8f3fbf2 commit 6210b16
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 53 deletions.
16 changes: 1 addition & 15 deletions README.md
Expand Up @@ -63,11 +63,6 @@ end
= invoke(:example_unit, :render_example)
```

```
-# app/units/example_unit/views/_example.html.slim
= foo
```

## Unit
You can see [the real example of an unit module file](https://github.com/cookpad/chanko/blob/master/spec/dummy/app/units/entry_deletion/entry_deletion.rb).

Expand Down Expand Up @@ -120,16 +115,7 @@ end
```

### render
The view path app/units/example_unit/views is added into view_paths in invoking.
So you can render app/units/example_unit/views/_example.html.slim in invoking.

```ruby
scope(:view) do
function(:render_example) do
render "/example", :foo => hello("world")
end
end
```
In its previous version, Chanko added the views path of the unit to Rails' view file search. However, it no longer does that. If you still want to place the views path under the unit, please create a symbolic link under app/views/units and refer to it.

### models
In models block, you can expand model features by `expand` method.
Expand Down
17 changes: 4 additions & 13 deletions lib/chanko/function.rb
Expand Up @@ -22,12 +22,10 @@ def initialize(unit, label, &block)

def invoke(context, options = {})
with_unit_stack(context) do
with_unit_view_path(context) do
capture_exception(context) do
result = context.instance_eval(&block)
result = decorate(result, context, options[:type]) if context.view? && result.present?
result
end
capture_exception(context) do
result = context.instance_eval(&block)
result = decorate(result, context, options[:type]) if context.view? && result.present?
result
end
end
end
Expand Down Expand Up @@ -59,13 +57,6 @@ def with_unit_stack(context)
context.units.pop
end

def with_unit_view_path(context)
context.view_paths.unshift unit.resolver if context.respond_to?(:view_paths)
yield
ensure
context.view_paths.paths.shift if context.respond_to?(:view_paths)
end

def capture_exception(context)
yield
rescue Exception => exception
Expand Down
23 changes: 0 additions & 23 deletions spec/chanko/function_spec.rb
Expand Up @@ -50,16 +50,6 @@ def path
end
end

let(:context_without_view_paths) do
Class.new do
include Chanko::Invoker

def units
@units ||= []
end
end.new
end

let(:options) do
{ :type => :plain }
end
Expand All @@ -68,19 +58,6 @@ def units
it "invokes block with given context and stacked unit" do
expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
end

context "when context is a view" do
it "invokes with unit's view path" do
expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
end
end

context "when context does not have view_paths" do
it "invokes successfully" do
expect(described_class.new(unit, :label) { "test" }.
invoke(context_without_view_paths, options)).to eq("test")
end
end
end
end
end
1 change: 1 addition & 0 deletions spec/dummy/app/views/units/example_unit
4 changes: 2 additions & 2 deletions spec/fixtures/units/example_unit/example_unit.rb
Expand Up @@ -27,7 +27,7 @@ module ExampleUnit
end

function(:render) do
render_to_string :partial => "/test", :locals => { :local => "test" }
render_to_string :partial => "/units/example_unit/test", :locals => { :local => "test" }
end

function(:nesting_locals_outer) do
Expand Down Expand Up @@ -78,7 +78,7 @@ module ExampleUnit
end

function(:render) do
render "/test", :local => "test"
render "/units/example_unit/test", :local => "test"
end

function(:blank) do
Expand Down

0 comments on commit 6210b16

Please sign in to comment.