DEV: improves rails plugin generator (#7949)
Fixes bugs, simplifies code, more default files. General idea, more is more here as it's easier to just delete things than reading and passing all the options.
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
import RestAdapter from "discourse/adapters/rest";
|
||||
|
||||
export default RestAdapter.extend({
|
||||
basePath() {
|
||||
return "/<%= dasherized_name %>/";
|
||||
}
|
||||
});
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
}
|
||||
});
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
}
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
export default Ember.Controller.extend({});
|
||||
@@ -0,0 +1,3 @@
|
||||
import RestModel from "discourse/models/rest";
|
||||
|
||||
export default RestModel.extend({});
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export default Discourse.Route.extend({
|
||||
controllerName: "actions-index",
|
||||
|
||||
model(params) {
|
||||
return this.store.findAll("action");
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render("actions-index");
|
||||
}
|
||||
});
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export default Discourse.Route.extend({
|
||||
controllerName: "actions-show",
|
||||
|
||||
model(params) {
|
||||
return this.store.find("action", params.id);
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render("actions-show");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
export default Discourse.Route.extend({
|
||||
controllerName: "actions",
|
||||
|
||||
renderTemplate() {
|
||||
this.render("actions");
|
||||
}
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
controller-index.hbs
|
||||
+1
@@ -0,0 +1 @@
|
||||
controller-show.hbs id: {{model.id}}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
controller.hbs
|
||||
|
||||
{{outlet}}
|
||||
@@ -0,0 +1,15 @@
|
||||
module <%= classified_name %>
|
||||
class ActionsController < ::ApplicationController
|
||||
requires_plugin <%= classified_name %>
|
||||
|
||||
before_action :ensure_logged_in
|
||||
|
||||
def index
|
||||
render_json_dump({ actions: [] })
|
||||
end
|
||||
|
||||
def show
|
||||
render_json_dump({ action: { id: params[:id] } })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
module <%= classified_name %>
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name "<%= classified_name %>".freeze
|
||||
isolate_namespace <%= classified_name %>
|
||||
|
||||
config.after_initialize do
|
||||
Discourse::Application.routes.append do
|
||||
mount ::<%= classified_name %>::Engine, at: "/<%= dasherized_name %>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
function initialize<%= classified_name %>(api) {
|
||||
<% if @options['help'] %>
|
||||
// see app/assets/javascripts/discourse/lib/plugin-api
|
||||
// for the functions available via the api object
|
||||
<% end %>
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "<%= dasherized_name %>",
|
||||
|
||||
initialize() {
|
||||
withPluginApi("0.8.24", initialize<%= classified_name %>);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
function initialize<%= classified_name %>(api) {
|
||||
// https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "<%= dasherized_name %>",
|
||||
|
||||
initialize() {
|
||||
withPluginApi("0.8.31", initialize<%= classified_name %>);
|
||||
}
|
||||
};
|
||||
@@ -1,51 +1,19 @@
|
||||
# name: <%= name %>
|
||||
# about:
|
||||
# about: <%= @about %>
|
||||
# version: 0.1
|
||||
# authors: <%= @github_username %>
|
||||
# url: https://github.com/<%= @github_username %>
|
||||
|
||||
<% if @options["stylesheet"] %>
|
||||
register_asset "stylesheets/common/<%= dasherized_name %>.scss"
|
||||
<% end %>
|
||||
register_asset "stylesheets/desktop/<%= dasherized_name %>.scss"
|
||||
register_asset "stylesheets/mobile/<%= dasherized_name %>.scss"
|
||||
|
||||
enabled_site_setting :<%= underscored_name %>_enabled
|
||||
|
||||
PLUGIN_NAME ||= "<%= name %>".freeze
|
||||
PLUGIN_NAME ||= "<%= classified_name %>".freeze
|
||||
|
||||
load File.expand_path('../lib/<%= dasherized_name %>/engine.rb', __FILE__)
|
||||
|
||||
after_initialize do
|
||||
<% if @options['help'] %>
|
||||
# see lib/plugin/instance.rb for the methods available in this context
|
||||
<% end %>
|
||||
|
||||
module ::<%= classified_name %>
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name PLUGIN_NAME
|
||||
isolate_namespace <%= classified_name %>
|
||||
end
|
||||
end
|
||||
|
||||
<% if @options["scheduled_job"] %>
|
||||
require File.expand_path("../jobs/scheduled/check_<%= underscored_name %>.rb", __FILE__)
|
||||
<% end %>
|
||||
|
||||
<% if @options["controller"] %>
|
||||
require_dependency "application_controller"
|
||||
class <%= name %>::ActionsController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
before_action :ensure_logged_in
|
||||
|
||||
def list
|
||||
render json: success_json
|
||||
end
|
||||
end
|
||||
|
||||
<%= name %>::Engine.routes.draw do
|
||||
get "/list" => "actions#list"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
mount ::<%= name %>::Engine, at: "/<%= dasherized_name %>"
|
||||
end
|
||||
<% end %>
|
||||
# https://github.com/discourse/discourse/blob/master/lib/plugin/instance.rb
|
||||
end
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
module <%= classified_name %>
|
||||
class <%= classified_name %>Controller < ::ApplicationController
|
||||
requires_plugin <%= classified_name %>
|
||||
|
||||
before_action :ensure_logged_in
|
||||
|
||||
def index
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function() {
|
||||
this.route("<%= dasherized_name %>", function() {
|
||||
this.route("actions", function() {
|
||||
this.route("show", { path: "/:id" });
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
class <%= classified_name %>Constraint
|
||||
def matches?(request)
|
||||
SiteSetting.<%= underscored_name %>_enabled
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require_dependency "<%= underscored_name %>_constraint"
|
||||
|
||||
<%= classified_name %>::Engine.routes.draw do
|
||||
get "/" => "<%= dasherized_name %>#index", constraints: <%= classified_name %>Constraint.new
|
||||
get "/actions" => "actions#index", constraints: <%= classified_name %>Constraint.new
|
||||
get "/actions/:id" => "actions#show", constraints: <%= classified_name %>Constraint.new
|
||||
end
|
||||
Reference in New Issue
Block a user