ScalesCms
ScalesCMS is a plugin CMS for the Phoenix Framework that is developed by Fish on Fire
and allows you to manage the content of either applications or websites easily.
It provides a set of JSON endpoints for headless usage. Alongside the CMS we also provide a set of
React Native components that can be used to easily integrate the CMS into your application.
Build Status
Prerequisites
- Elixir 1.14
- Phoenix 1.7.17 and higher
How to set up in your project
-
Add to the list of dependencies in
mix.exs -
Add the following lines to your config.exs file
This will allow the CMS to use your application's endpoint and repo.config :scales_cms, endpoint: CmsDemoWeb.Endpoint config :scales_cms, repo: CmsDemo.Repo -
Run
mix scales_cms.generate_migrationsto generate the migrations for the CMS. These migrations are now part of your application. You could modify them, but no modifications are supported currently. -
Run
mix ecto.migrateto run the migrations.
Setup tailwind for the admin interface
-
Add
tailwindto your list of dependencies inmix.exs -
Run
mix tailwind.installto install tailwind -
Add the following lines to your
config.exsfileconfig :tailwind, version: "3.3.2", default: [ args: ~w( --config=tailwind.config.js --input=css/app.css --output=../priv/static/assets/app.css ), cd: Path.expand("../assets", __DIR__) ] -
Create a
tailwind.config.jsfile in the root of your project with the following content:// See the Tailwind configuration guide for advanced usage // https://tailwindcss.com/docs/configuration const plugin = require("tailwindcss/plugin") const fs = require("fs") const path = require("path") const defaultTheme = require('tailwindcss/defaultTheme') module.exports = { content: [ "./js/**/*.js", "../lib/scales_cms_web.ex", "../lib/scales_cms_web/**/*.*ex" ], theme: { extend: { fontFamily: { 'sans': ['"Poppins"', ...defaultTheme.fontFamily.sans], }, colors: { primary: "#21C39D", primary_dark: "#178B70", secondary: "#0C2136", secondary_light: "#0F172A80", black: "#151519", midGrey: "#4D5D74", lightGrey: "#E7EAEE", white: "#FFFFFF", purple: "#C711B8", yellow: "#FFBB34", blue: "#36A1FF", } }, }, plugins: [ require('flowbite/plugin'), require("@tailwindcss/forms"), // Allows prefixing tailwind classes with LiveView classes to add rules // only when LiveView classes are applied, for example: // // <div class="phx-click-loading:animate-ping"> // plugin(({ addVariant }) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])), plugin(({ addVariant }) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])), plugin(({ addVariant }) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])), // Embeds Heroicons (https://heroicons.com) into your app.css bundle // See your `CoreComponents.icon/1` for more information. // plugin(function ({ matchComponents, theme }) { let iconsDir = path.join(__dirname, "../deps/heroicons/optimized") let values = {} let icons = [ ["", "/24/outline"], ["-solid", "/24/solid"], ["-mini", "/20/solid"], ["-micro", "/16/solid"] ] icons.forEach(([suffix, dir]) => { fs.readdirSync(path.join(iconsDir, dir)).forEach(file => { let name = path.basename(file, ".svg") + suffix values[name] = { name, fullPath: path.join(iconsDir, dir, file) } }) }) matchComponents({ "hero": ({ name, fullPath }) => { let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "") let size = theme("spacing.6") if (name.endsWith("-mini")) { size = theme("spacing.5") } else if (name.endsWith("-micro")) { size = theme("spacing.4") } return { [`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`, "-webkit-mask": `var(--hero-${name})`, "mask": `var(--hero-${name})`, "mask-repeat": "no-repeat", "background-color": "currentColor", "vertical-align": "middle", "display": "inline-block", "width": size, "height": size } } }, { values }) }) ] } -
Create a
cssfolder in theassetsfolder and create anapp.cssfile with the following content:@tailwind base; @tailwind components; @tailwind utilities; /* Import the scales_cms Tailwind CSS file */ @import "../../deps/scales_cms/priv/tailwind/scales_cms.css"; /* This file is for your main application CSS */
React Native Renderer
More info on https://github.com/fishonfire/react-native-scales-renderer
Development setup
Prerequisites:
direnv is used to manage environment variables. You can install it by running:
curl -sfL https://direnv.net/install.sh | bashecho 'eval "$(direnv hook bash)"' >> ~/.bashrcorecho 'eval "$(direnv hook zsh)"' >> ~/.zshrc-
Restart your terminal or run
source ~/.bashrcorsource ~/.zshrc
To start your Phoenix server:
-
Run
mix guardian.gen.secretto generate API secret -
Set the API secret in the
.envrcfile like this:export API_SECRET_KEY=+wUAu+Hizgp+rIBZdK8wM2HKYkHT1V6PvrYEoGJybMeH7/VqerwfF8Inw1Cq083W
-
Run
direnv allowto load the environment variables -
Run
mix setupto install and setup dependencies -
Start Phoenix endpoint with
mix phx.serveror inside IEx withiex -S mix phx.server
Now you can visit localhost:4000 from your browser.
Contributors
- Simon de la Court (https://github.com/simondelacourt)
- Alexey Pikulik (https://github.com/alexeyfof)
- Menno Jongejan (https://github.com/mennolpFoF)
Copyright and Licence
Copyright (c) 2024, Fish on Fire.
Phoenix source code is licensed under the GPL License.