Current section
37 Versions
Jump to
Current section
37 Versions
Compare versions
22
files changed
+441
additions
-79
deletions
| @@ -1,13 +1,13 @@ | |
| 1 | - # Thesis Content Editing System |
| 1 | + # Thesis |
| 2 2 | |
| 3 3 | [](https://semaphoreci.com/ir/thesis-phoenix) |
| 4 4 | |
| 5 | - Thesis is a lightweight and flexible Elixir/Phoenix hex package for quickly and easily |
| 6 | - adding content editing to any page on a Phoenix website. |
| 5 | + Thesis is a lightweight and flexible Elixir/Phoenix CMS for quickly and easily |
| 6 | + adding content editing to any page on a Phoenix website, as well as creating new |
| 7 | + dynamically routed pages. It's ideal for either adding limited editing support to |
| 8 | + existing Phoenix websites or building dynamic websites. |
| 7 9 | |
| 8 | - It's not quite a Phoenix CMS, so we call it a Phoenix CES -- content editing system. |
| 9 | - |
| 10 | - See also the Thesis [Rails gem](https://github.com/infinitered/thesis-rails). |
| 10 | + _See also the Thesis [Rails gem](https://github.com/infinitered/thesis-rails)._ |
| 11 11 | |
| 12 12 |  |
| 13 13 | |
| @@ -21,6 +21,7 @@ See also the Thesis [Rails gem](https://github.com/infinitered/thesis-rails). | |
| 21 21 | * Image URL editing, both `img` tag and `div` with background image |
| 22 22 | * Page meta title and description editing |
| 23 23 | * Easily bring your own authentication system in one tiny function |
| 24 | + * Create new dynamic pages, delete dynamic pages |
| 24 25 | |
| 25 26 | ## Installation and Configuration |
| 26 27 | |
| @@ -30,7 +31,7 @@ _If you are having problems, view `README_INSTALL.md` for manual instructions._ | |
| 30 31 | |
| 31 32 | ```elixir |
| 32 33 | def deps do |
| 33 | - [{:thesis, "~> 0.0.20"}] |
| 34 | + [{:thesis, "~> 0.0.21"}] |
| 34 35 | end |
| 35 36 | |
| 36 37 | def application do |
| @@ -215,6 +216,56 @@ def about(conn, params) do | |
| 215 216 | end |
| 216 217 | ``` |
| 217 218 | |
| 219 | + ## Dynamic Pages |
| 220 | + |
| 221 | + Thesis supports users creating and deleting dynamically routed pages. These |
| 222 | + differ from static pages in that they are routed by Thesis rather than Phoenix, |
| 223 | + and live only in your database. They can be rendered with different templates. |
| 224 | + |
| 225 | +  |
| 226 | + |
| 227 | + To enable dynamic pages, add (or uncomment) this in your `config/config.exs` file: |
| 228 | + |
| 229 | + ```elixir |
| 230 | + config :thesis, :dynamic_pages, |
| 231 | + view: <MyApp>.DynamicView, |
| 232 | + templates: ["index.html", "otherview.html"], |
| 233 | + not_found_view: <MyApp>.ErrorView, |
| 234 | + not_found_template: "404.html" |
| 235 | + ``` |
| 236 | + |
| 237 | + Replace `<MyApp>` with your app name. Use any view you want, and put any templates |
| 238 | + contained in that view that you want to make available in the `templates` list. |
| 239 | + These will be displayed as a drop-down to the user when they are creating the new |
| 240 | + dynamic page. |
| 241 | + |
| 242 | + You'll also need to make one change to your router.ex and a controller of your |
| 243 | + choice. |
| 244 | + |
| 245 | + ```elixir |
| 246 | + # web/router.ex |
| 247 | + |
| 248 | + get "/*path", <MyApp>.PageController, :dynamic |
| 249 | + |
| 250 | + # web/controllers/page_controller.ex (or similar) |
| 251 | + |
| 252 | + def dynamic(conn, _params) do |
| 253 | + render_dynamic(conn) |
| 254 | + end |
| 255 | + ``` |
| 256 | + |
| 257 | + You can pass in a default template (otherwise, it'll use the first template |
| 258 | + option in your config) with `render_dynamic(conn, template: "index.html")`. |
| 259 | + |
| 260 | + You can choose to make only a portion of your website support static pages by |
| 261 | + routing more specifically. For example, if you want a blog section: |
| 262 | + |
| 263 | + ```elixir |
| 264 | + # web/router.ex |
| 265 | + |
| 266 | + get "/blog/*path", <MyApp>.BlogController, :dynamic |
| 267 | + ``` |
| 268 | + |
| 218 269 | ## Authorization |
| 219 270 | |
| 220 271 | You probably don't want your website editable by the world. Thesis doesn't |
| @@ -6,7 +6,7 @@ For automatic setup, see `README.md`. | |
| 6 6 | |
| 7 7 | ```elixir |
| 8 8 | def deps do |
| 9 | - [{:thesis, "~> 0.0.20"}] |
| 9 | + [{:thesis, "~> 0.0.21"}] |
| 10 10 | end |
| 11 11 | |
| 12 12 | def application do |
| @@ -23,6 +23,12 @@ config :thesis, | |
| 23 23 | store: Thesis.EctoStore, |
| 24 24 | authorization: <MyApp>.ThesisAuth |
| 25 25 | config :thesis, Thesis.EctoStore, repo: <MyApp>.Repo |
| 26 | + # If you want to allow creating dynamic pages: |
| 27 | + # config :thesis, :dynamic_pages, |
| 28 | + # view: <MyApp>.DynamicView, |
| 29 | + # templates: ["index.html", "otherview.html"], |
| 30 | + # not_found_view: <MyApp>.ErrorView, |
| 31 | + # not_found_template: "404.html" |
| 26 32 | # If you want to use Ospry.io file uploads: |
| 27 33 | # config :thesis, Thesis.OspryUploader, |
| 28 34 | # ospry_public_key: "pk-prod-asdfasdfasdfasdfasdf" |
| @@ -16,6 +16,7 @@ | |
| 16 16 | <<"priv/static/thesis-editor.js">>,<<"priv/static/thesis.css">>, |
| 17 17 | <<"priv/templates/thesis.install/add_indexes_to_tables.exs">>, |
| 18 18 | <<"priv/templates/thesis.install/add_meta_to_thesis_page_contents.exs">>, |
| 19 | + <<"priv/templates/thesis.install/add_template_and_redirect_url_to_thesis_pages.exs">>, |
| 19 20 | <<"priv/templates/thesis.install/create_thesis_tables.exs">>, |
| 20 21 | <<"priv/templates/thesis.install/thesis_auth.exs">>, |
| 21 22 | <<"web/static/css/_extends/_extends.sass">>, |
| @@ -127,11 +128,12 @@ | |
| 127 128 | <<"web/static/js/content_types/raw_html_tray.js">>, |
| 128 129 | <<"web/static/js/content_types/text_editor.js">>, |
| 129 130 | <<"web/static/js/thesis-editor.js">>,<<"web/static/js/utilities/net.js">>, |
| 130 | - <<"web/static/js/utilities/ospry.js">>,<<"mix.exs">>,<<"README.md">>, |
| 131 | + <<"web/static/js/utilities/ospry.js">>, |
| 132 | + <<"web/templates/test/test.html.eex">>,<<"mix.exs">>,<<"README.md">>, |
| 131 133 | <<"README_INSTALL.md">>,<<"LICENSE.md">>,<<"package.json">>]}. |
| 132 134 | {<<"licenses">>,[<<"MIT">>]}. |
| 133 135 | {<<"links">>, |
| 134 | - [{<<"Docs">>,<<"https://hexdocs.pm/thesis/0.0.20/api-reference.html">>}, |
| 136 | + [{<<"Docs">>,<<"https://hexdocs.pm/thesis/0.0.21/api-reference.html">>}, |
| 135 137 | {<<"GitHub">>,<<"https://github.com/infinite_red/thesis">>}]}. |
| 136 138 | {<<"maintainers">>, |
| 137 139 | [<<"Jamon Holmgren">>,<<"Ken Miller">>,<<"Daniel Berkompas">>]}. |
| @@ -161,4 +163,4 @@ | |
| 161 163 | {<<"name">>,<<"html_sanitize_ex">>}, |
| 162 164 | {<<"optional">>,false}, |
| 163 165 | {<<"requirement">>,<<">= 1.0.1">>}]]}. |
| 164 | - {<<"version">>,<<"0.0.20">>}. |
| 166 | + {<<"version">>,<<"0.0.21">>}. |
| @@ -5,7 +5,8 @@ defmodule Mix.Tasks.Thesis.Install do | |
| 5 5 | @migrations [ |
| 6 6 | "create_thesis_tables", |
| 7 7 | "add_meta_to_thesis_page_contents", |
| 8 | - "add_indexes_to_tables" |
| 8 | + "add_indexes_to_tables", |
| 9 | + "add_template_and_redirect_url_to_thesis_pages" |
| 9 10 | ] |
| 10 11 | @template_files [ |
| 11 12 | {"priv/templates/thesis.install/thesis_auth.exs", "lib/thesis_auth.ex" } |
| @@ -37,7 +38,6 @@ defmodule Mix.Tasks.Thesis.Install do | |
| 37 38 | |
| 38 39 | @doc false |
| 39 40 | def thesis_templates do |
| 40 | - migrations = ["create_thesis_tables", "add_meta_to_thesis_page_contents"] |
| 41 41 | migration_files = @migrations |
| 42 42 | |> Enum.filter(&migration_missing?/1) |
| 43 43 | |> Enum.with_index |
| @@ -98,6 +98,12 @@ defmodule Mix.Tasks.Thesis.Install do | |
| 98 98 | store: Thesis.EctoStore, |
| 99 99 | authorization: #{Mix.Phoenix.base}.ThesisAuth |
| 100 100 | config :thesis, Thesis.EctoStore, repo: #{Mix.Phoenix.base}.Repo |
| 101 | + # If you want to allow creating dynamic pages: |
| 102 | + # config :thesis, :dynamic_pages, |
| 103 | + # view: #{Mix.Phoenix.base}.DynamicView, |
| 104 | + # templates: ["index.html", "otherview.html"], |
| 105 | + # not_found_view: #{Mix.Phoenix.base}.ErrorView, |
| 106 | + # not_found_template: "404.html" |
| 101 107 | # If you want to use Ospry.io file uploads: |
| 102 108 | # config :thesis, Thesis.OspryUploader, |
| 103 109 | # ospry_public_key: "pk-prod-asdfasdfasdfasdfasdf" |
| @@ -8,11 +8,16 @@ defmodule Thesis.ApiController do | |
| 8 8 | |
| 9 9 | def assets(conn, _params), do: conn |
| 10 10 | |
| 11 | - def update(conn, %{"contents" => contents, "page" => page} = _params) do |
| 11 | + def update(conn, %{"contents" => contents, "page" => page}) do |
| 12 12 | :ok = store.update(page, contents) |
| 13 13 | json conn, %{} |
| 14 14 | end |
| 15 15 | |
| 16 | + def delete(conn, %{"path" => path}) do |
| 17 | + :ok = store.delete(%{"slug" => path}) |
| 18 | + json conn, %{} |
| 19 | + end |
| 20 | + |
| 16 21 | defp ensure_authorized!(conn, _params) do |
| 17 22 | if auth.page_is_editable?(conn), do: conn, else: put_unauthorized(conn) |
| 18 23 | end |
Loading more files…