analytics/lib/plausible_web.ex

90 lines
2.1 KiB
Elixir
Raw Normal View History

2019-09-02 14:29:19 +03:00
defmodule PlausibleWeb do
def controller do
quote do
use Phoenix.Controller, namespace: PlausibleWeb
import Plug.Conn
import PlausibleWeb.ControllerHelpers
alias PlausibleWeb.Router.Helpers, as: Routes
end
end
def view do
quote do
use Phoenix.View,
root: "lib/plausible_web/templates",
namespace: PlausibleWeb
# Import convenience functions from controllers
import Phoenix.Controller, only: [view_module: 1]
2019-09-02 14:29:19 +03:00
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
use Phoenix.Component
2021-01-13 18:04:01 +03:00
2019-09-02 14:29:19 +03:00
import PlausibleWeb.ErrorHelpers
2022-03-24 13:25:07 +03:00
import PlausibleWeb.FormHelpers
import PlausibleWeb.Components.Generic
2019-09-02 14:29:19 +03:00
alias PlausibleWeb.Router.Helpers, as: Routes
end
end
def router do
quote do
use Phoenix.Router
import Plug.Conn
import Phoenix.Controller
end
end
def channel do
quote do
use Phoenix.Channel
end
end
def plugins_api_controller do
quote do
use Phoenix.Controller, namespace: PlausibleWeb.Plugins.API
import Plug.Conn
import PlausibleWeb.Plugins.API.Router.Helpers
import PlausibleWeb.Plugins.API, only: [base_uri: 0]
alias PlausibleWeb.Plugins.API.Schemas
alias PlausibleWeb.Plugins.API.Views
Plugins API: 2nd pass with Goals resource + SharedLinks schema changes (#3396) * Remove "Context" namespace level * Change Goal string representation * Alias Schemas in Plugin API Test Case template * Update schema & tests for SharedLink resource * Update Goals interface - make it possible to create revenue goals - extract "for site" query to a standalone function * Fixup typespecs * Alias Errors module in OpenAPI controllers * Add missing goals test * Implement Goals Plugins API resource * Add extra test to confirm changeset error propagation * Mute credo * Fix typos * Handle changeset traversal in `Errors` * Use upserts in `Goals.find_or_create` * Extract touch_site! to Site.Cache, address credo, improve code docs * Apply formatting * Remove unused inner join * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update error message on revenue goal currency clash * Remove unused code --------- Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2023-10-05 12:54:18 +03:00
alias PlausibleWeb.Plugins.API.Errors
alias Plausible.Plugins.API
plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true, replace_params: false)
use OpenApiSpex.ControllerSpecs
end
end
def plugins_api_view do
quote do
use Phoenix.View,
namespace: PlausibleWeb.Plugins.API,
root: ""
alias PlausibleWeb.Plugins.API.Router.Helpers
import PlausibleWeb.Plugins.API.Views.Pagination, only: [render_metadata_links: 4]
end
end
def open_api_schema do
quote do
require OpenApiSpex
alias OpenApiSpex.Schema
alias PlausibleWeb.Plugins.API.Schemas
end
end
2019-09-02 14:29:19 +03:00
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end