hyperstack-org / hyperstack-org/hyperstack

remove rails dependencies

オープン
#340 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
JavaScript
スター
538
フォーク
41
PR マージ指標
30日以内にマージされた PR はありません

説明

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
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。