hyperstack-org / hyperstack-org/hyperstack

remove rails dependencies

Đang mở
#340 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hyperspec should depend on Rack rather than Rails, but still integrate with Rails if in a Rails environment.

*HyperSpec*

HyperSpec can now be run on top of Rack, and only optionally integrates with Rails.

*HyperComponent*

HyperComponent uses React-Rails to implement pre-rendering. However according to the React-Rails repo, there is no longer any dependency on Rails per se. Another option is have a look at https://github.com/prerender/prerender_rails, which may be a much better option going forward.

However, atm If Rails is not present, then you don't get any prerendering and everything else works. So this is not a hard dependency anyway.

*HyperOperation*

It should be possible to redo hyper-operation so that it is just a rack middle ware. There a few places it needs the "controller" to get things like x-csrf-token.

However there needs to be some way to get the acting_user which is currently assumed to be a method on ApplicationController, but I guess its all wound upwith how you would implement a session outside of rails. Any comments on how people do this in other Rack Frameworks would be appreciated.

*HyperModel*

This should depend only on hyper-operation for xport and active record, not rails, so once HyperOperation depends only on Rack, then HyperModel may be just done. However it is still very tied to ActiveRecord, but there is no problem using AR outside of Rails.

Some ideas on implementation details:

Rails dependencies go in files named rails.rb, inside of the gem's libs. That file then requires the rest of the gem. So hyper-component/rails would start with `require hyper-component`, and then have any rails specific dependencies.

Or we can continue to use the mechanism of checking for the existing of rails, before adding rails features.

Found this nice SO answer on how a gem can link in a middleware into rails:

https://stackoverflow.com/questions/5729737/automatically-add-rack-middleware-with-a-gem

```ruby
require "tbbc/railtie" if defined? Rails in the outer file...

module TBBC
class Railtie < Rails::Railtie
initializer "tbbc.insert_middleware" do |app|
app.config.middleware.use "TBBC::Editor::Middleware"
end
end
end
```

I have also discovered that this seems to work to expand action view tags outside of the controller. No idea how robust it is.

```
def self.action_view
@action_view ||= ActionView::Base.new
end

def application!
@page = "#{self.class.action_view.javascript_include_tag('application')}\n#{@page}"
end
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.