Module: UniRails

Defined in:
lib/uni_rails.rb,
lib/uni_rails/app.rb,
lib/uni_rails/app/css.rb,
lib/uni_rails/helpers.rb,
lib/uni_rails/version.rb,
lib/uni_rails/app/views.rb,
lib/uni_rails/app/javascript.rb,
lib/uni_rails/helpers/css_helper.rb,
lib/uni_rails/helpers/javascript_helper.rb

Defined Under Namespace

Modules: Helpers Classes: App, Error

Constant Summary collapse

VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.css(content) ⇒ Object



85
86
87
# File 'lib/uni_rails.rb', line 85

def self.css(content)
  UniRails::App::CSS.css = content
end

.enable_turbo_rails!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/uni_rails.rb', line 24

def self.enable_turbo_rails!
  # # We currently do not support ActionCable and ActiveJob
  require "turbo-rails"

  App.configure do
    initializer "turbo.no_action_cable", before: :set_eager_load_paths do
      unless defined?(ActionCable)
        Rails.autoloaders.once.do_not_eager_load("#{Turbo::Engine.root}/app/channels")
      end

      unless defined?(ActiveJob)
        Rails.autoloaders.once.do_not_eager_load("#{Turbo::Engine.root}/app/jobs")
      end
    end
  end

  App::Javascript.dependencies.merge!(
    "turbo" => "https://unpkg.com/@hotwired/[email protected]/dist/turbo.es2017-umd.js"
  )
end

.import_maps(dependencies) ⇒ Object



77
78
79
# File 'lib/uni_rails.rb', line 77

def self.import_maps(dependencies)
  UniRails::App::Javascript.dependencies.merge! dependencies
end

.javascript(content) ⇒ Object



81
82
83
# File 'lib/uni_rails.rb', line 81

def self.javascript(content)
  UniRails::App::Javascript.javascript = content
end

.rackup_handlerObject



58
59
60
61
62
63
# File 'lib/uni_rails.rb', line 58

def self.rackup_handler
  @@rackup_handler ||= begin
    require 'rackup'
    Rackup::Handler::WEBrick
  end
end

.rackup_handler=(handler) ⇒ Object



54
55
56
# File 'lib/uni_rails.rb', line 54

def self.rackup_handler=(handler)
  @@rackup_handler = handler
end

.register_view(action, view) ⇒ Object



65
66
67
# File 'lib/uni_rails.rb', line 65

def self.register_view(action, view)
  UniRails::App::Views.instance.views[action] = view
end

.routes(&block) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/uni_rails.rb', line 45

def self.routes(&block)
  App.initializer :add_uni_routes, before: :add_internal_routes do |app|
    app.routes.prepend do
      get "/rails/info/routes" => "rails/info#routes", internal: true
    end
    app.routes.prepend(&block)
  end
end

.run(**webrick_options) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/uni_rails.rb', line 69

def self.run(**webrick_options)
  App.initialize!
  rackup_handler.run App, **webrick_options
  # Rackup::Handler::Falcon.run App, **webrick_options
  # Rack::Handler::Puma.run App, **webrick_options
  # Rackup::Handler::WEBrick.run App, **webrick_options
end