75 lines
2.2 KiB
Ruby
75 lines
2.2 KiB
Ruby
require "active_hash"
|
|
require "ruby2js"
|
|
require "ruby2js/es2015"
|
|
require "ruby2js/filter/functions"
|
|
require "ruby2js/haml"
|
|
require "ruby2js/filter/vue"
|
|
require "merged/shared_helper"
|
|
|
|
module Merged
|
|
class Engine < ::Rails::Engine
|
|
isolate_namespace Merged
|
|
config.merged = Merged
|
|
|
|
initializer "merged.assets.precompile" do |app|
|
|
app.config.assets.precompile += %w( merged/merged.css merged/merged.email.css
|
|
merged/home merged/merged_logo)
|
|
add_image_assets(app.config , "section_preview")
|
|
add_image_assets(app.config , "card_preview")
|
|
end
|
|
|
|
initializer "after_initialize" do |app|
|
|
ActiveSupport::Reloader.to_prepare do
|
|
end
|
|
end
|
|
|
|
private
|
|
def add_image_assets(config , sub_dir )
|
|
dir = Dir.new(Engine.root.join("app/assets/images/merged/" , sub_dir))
|
|
dir.children.each do |file|
|
|
kid = "merged/" + sub_dir + "/" + file
|
|
config.assets.precompile << kid
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
module ActionDispatch::Routing
|
|
class Mapper
|
|
|
|
# merged_routes will draw neccessary routes and possibly mount engine
|
|
# This includes:
|
|
# post /form for form processing
|
|
# get /news/:id for any news posts
|
|
# get /:id for any pages
|
|
# redirects from any renamed page
|
|
# root to /index unless options[:root] == false
|
|
# mount the engine (make editing possible) unless production
|
|
# or oprions[:production] == true (not recommended)
|
|
def merged_routes options = {}
|
|
Rails.application.routes.draw do
|
|
if options[:root]
|
|
root "merged/view#page" , id: 'index'
|
|
end
|
|
|
|
Merged::Page.all.each do |page|
|
|
next unless page.redirects
|
|
page.redirects.split.each do |old|
|
|
next if old == page.name
|
|
get "/#{old}" => redirect("/#{page.name}")
|
|
end
|
|
end
|
|
|
|
post "/form" , to: "merged/form#post" , as: :post_form
|
|
get "/news/:id" , to: "merged/view#page" , id: :id , as: :view_blog
|
|
get ":id" , to: "merged/view#page" , id: :id , as: :view_page
|
|
|
|
engine_path = options[:path] || "/merged"
|
|
if ! Rails.env.production? or options[:production].present?
|
|
mount Merged::Engine => engine_path
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|