Thesis
Thesis is an Elixir/Phoenix hex package for quickly and easily adding content editing to any page.
It's inspired by the Rails gem by the same name and author.
Installation and Configuration
If you are having problems, view README_INSTALL.md for manual instructions.
1. Add thesis to your mix.exs:
def deps do
[{:thesis, "~> 0.0.5"}]
end
def application do
[applications: [:thesis]]
end
2. Run mix thesis.install
This install script will add Thesis to your config.exs and web.ex, as well
as generate a migration and an authorization module in lib/thesis_auth.ex.
3. Add the Thesis editor to your layout
<body>
<%= thesis_editor(@conn) %>
4. Run mix ecto.migrate
$ mix ecto.migrate
Making Pages Editable
Use the Thesis.View.content/4 view helper function to make a content area
editable. If you added use Thesis.View in your web.ex file, this function
is already available on all of your views.
Thesis will add a wrapper <div> around editable HTML and plain-text content
areas.
Rich Text Areas
Simply wrap your HTML in a content function call.
<h1>Title</h1>
<p>
Here's my default description!
</p>
becomes...
<%= content(@conn, "Section identifier", :html) do %>
<h1>Title</h1>
<p>
Here's my default description!
</p>
<% end %>
Plain Text Areas
For plain-text, provide a do: option for default text.
<h1>My Title</h1>
becomes...
<h1><%= content(@conn, "Title identifier", :text, do: "My Title") %></h1>
Authorization
You probably don't want your website editable by the world. Thesis doesn't
force you to use any particular authorization strategy. Instead, Thesis will
call your auth module's can_edit_page?/1 function and provide the current
conn, which can be used to extract current user session data, the current
page, and then decide on your own how that should affect authorization.
Here's an example which we use on our own website, https://infinite.red:
defmodule IrWebsite.ThesisAuth do
def page_is_editable?(conn) do
!!IrWebsite.AuthController.current_user(conn)
end
end
In our auth_controller.ex file, the current_user/1 function looks like this:
def current_user(conn) do
get_session(conn, :current_user)
end
So, in this case, we're simply checking to see if the user has been logged in or not. Since we're verifying their identity before letting them log in, it's safe for us to assume that if they're logged in, they have permission to edit the page.
What Thesis Isn't
You can't have it all. Thesis isn't the same as other -bloated- full-functional content management systems out there. This is a list of what it's not now and not likely to be in the future.
We reserve the right to change our mind, however. :-)
- Not a WordPress Replacement
- Not a full featured CMS
- Not a full featured WYSIWYG editor
- Not an authentication or permission system
- Not a library that works well outside of Phoenix
Contributing
We're committed to making Thesis the go-to content editing system for Phoenix websites. Please help us improve!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Write tests for your new feature
- Run
rake specin the root directory to ensure that all tests pass. - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Key Contributors
- Jamon Holmgren @jamonholmgren
- Ken Miller @seriousken
- Daniel Berkompas @dberkom
Also supported by others on the Infinite Red team.
License
Copyright (c) 2016 Infinite Red, Inc.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.