diff --git a/README.md b/README.md index 67d7d39..e48ac87 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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. diff --git a/lib/chanko/function.rb b/lib/chanko/function.rb index a49e6b1..9e35ce3 100644 --- a/lib/chanko/function.rb +++ b/lib/chanko/function.rb @@ -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 @@ -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 diff --git a/lib/chanko/unit.rb b/lib/chanko/unit.rb index da1f31c..4cd5927 100644 --- a/lib/chanko/unit.rb +++ b/lib/chanko/unit.rb @@ -70,10 +70,6 @@ def to_prefix UnitProxy.generate_prefix(unit_name) end - def view_path - Rails.root.join("#{Config.units_directory_path}/#{unit_name}/views").to_s - end - def find_function(identifier, label) scope = ScopeFinder.find(identifier) target = scope.ancestors.find {|klass| scopes[klass] } @@ -93,10 +89,6 @@ def shared_methods @shared_methods ||= {} end - def resolver - @resolver ||= Config.resolver.new(view_path) - end - def extender @extender ||= Extender.new(to_prefix) end diff --git a/lib/generators/chanko/unit/templates/unit.rb.erb b/lib/generators/chanko/unit/templates/unit.rb.erb index 8d555b8..f3feb37 100644 --- a/lib/generators/chanko/unit/templates/unit.rb.erb +++ b/lib/generators/chanko/unit/templates/unit.rb.erb @@ -34,13 +34,11 @@ module <%= class_name %> # ``` # ## render - # In addition, the view path "<%= "#{directory}/views" %>" is added into view_paths. - # So you can render <%= "#{directory}/views/_example.html.erb" %> in invoking. - # + # You want to place the views path under the unit, please create a symbolic link under app/views/units and refer to it. # ``` # scope(:view) do # function(:function_name) do - # render "/example", :foo => "bar" + # render "/units/<%= your_unit_name.underscore %>/example", :foo => "bar" # end # end # ``` diff --git a/spec/chanko/function_spec.rb b/spec/chanko/function_spec.rb index 1fec5ae..c3e49c9 100644 --- a/spec/chanko/function_spec.rb +++ b/spec/chanko/function_spec.rb @@ -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 @@ -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 diff --git a/spec/chanko/unit_spec.rb b/spec/chanko/unit_spec.rb index 7d9aec9..543a18f 100644 --- a/spec/chanko/unit_spec.rb +++ b/spec/chanko/unit_spec.rb @@ -245,11 +245,5 @@ def self.has_one(name, *args) expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"]) end end - - describe ".view_path" do - it "returns path for its view directory" do - expect(unit.view_path).to eq("#{Config.units_directory_path}/example_unit/views") - end - end end end diff --git a/spec/dummy/app/views/units/example_unit b/spec/dummy/app/views/units/example_unit new file mode 120000 index 0000000..904d7b2 --- /dev/null +++ b/spec/dummy/app/views/units/example_unit @@ -0,0 +1 @@ +../../../../fixtures/units/example_unit/views \ No newline at end of file diff --git a/spec/fixtures/units/example_unit/example_unit.rb b/spec/fixtures/units/example_unit/example_unit.rb index 15bcc2f..5c67db7 100644 --- a/spec/fixtures/units/example_unit/example_unit.rb +++ b/spec/fixtures/units/example_unit/example_unit.rb @@ -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 @@ -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