{"id":13509131,"url":"https://github.com/nurugger07/calliope","last_synced_at":"2025-05-16T14:07:23.015Z","repository":{"id":10802825,"uuid":"13075238","full_name":"nurugger07/calliope","owner":"nurugger07","description":"An elixir haml parser","archived":false,"fork":false,"pushed_at":"2024-09-05T21:09:45.000Z","size":171,"stargazers_count":195,"open_issues_count":21,"forks_count":38,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-07T18:17:30.745Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nurugger07.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-24T20:00:42.000Z","updated_at":"2025-05-05T21:38:12.000Z","dependencies_parsed_at":"2024-11-13T15:50:48.822Z","dependency_job_id":null,"html_url":"https://github.com/nurugger07/calliope","commit_stats":{"total_commits":130,"total_committers":26,"mean_commits":5.0,"dds":0.7846153846153846,"last_synced_commit":"3c888312ec33c0b4da20cd64f0a8e8647a47e094"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nurugger07%2Fcalliope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nurugger07%2Fcalliope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nurugger07%2Fcalliope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nurugger07%2Fcalliope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nurugger07","download_url":"https://codeload.github.com/nurugger07/calliope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:01:03.379Z","updated_at":"2025-05-16T14:07:22.997Z","avatar_url":"https://github.com/nurugger07.png","language":"Elixir","funding_links":[],"categories":["Templating","Text and Numbers"],"sub_categories":[],"readme":"![Calliope](http://f.cl.ly/items/0T3a1a1w472z2o3p0d3O/6660441229_f6503a0dd2_b.jpg)\n\n# Calliope - An Elixir Haml Parser [![Build Status](https://travis-ci.org/nurugger07/calliope.png?branch=master)](https://travis-ci.org/nurugger07/calliope)\n\nFor those of you that prefer the poetic beauty of [HAML](https://github.com/haml/haml) templates over HTML, then Calliope is the package for you. Calliope is a parser written in [Elixir](http://elixir-lang.org/) that will render HAML/Elixir templates into HTML. For example, we can render the following HAML:\n\n``` haml\n!!! 5\n%html{lang: \"en-US\"}\n  %head\n    %title Welcome to Calliope\n  %body\n    %h1 Calliope\n    %h2 The muse of epic poetry\n```\n\nInto this HTML:\n\n``` html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en-US\"\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eWelcome to Calliope\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eCalliope\u003c/h1\u003e\n    \u003ch2\u003eThe muse of epic poetry\u003c/h2\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Using\n\n\nCalliope is simple to add to any project. If you are using the hex package manager, just add the following to your mix file:\n\n``` elixir\ndef deps do\n  [ { :calliope, '~\u003e 0.4.2' } ]\nend\n```\n\nIf you aren't using hex, add the reference to the github repo.\n\n``` elixir\ndef deps do\n  [ { :calliope, github: \"nurugger07/calliope\" } ]\nend\n```\n\nThen run `mix deps.get` in the shell to fetch and compile the dependencies. Then you can either call to Calliope directly:\n\n``` shell\niex(1)\u003e Calliope.render \"%h1 Welcome to Calliope\"\n\"\u003ch1\u003eWelcome to Calliope\u003c/h1\u003e\"\n```\n\nOr you can `use` Calliope in a module and call through your module:\n\n``` elixir\ndefmodule MyModule do\n  use Calliope\nend\n```\n\n``` shell\niex(1)\u003e MyModule.render \"%h1 Welcome to Calliope\"\n\"\u003ch1\u003eWelcome to Calliope\u003c/h1\u003e\"\n```\n\n## Formating\n\nIf you are not familiar with HAML syntax I would suggest you checkout the [reference](http://haml.info/docs/yardoc/file.REFERENCE.html) page. Most of the syntax has been accounted for but we are in the process of adding more functionality.\n\nHAML is basically a whitespace sensitive shorthand for HTML that does not use end-tags. Although Calliope uses HAML formating, it does use its own flavor. Sounds great but what does it look like:\n\n``` haml\n%tag{ attr: \"\", attr: \"\" } Content\n```\n\nOr you could use the following:\n\n``` haml\n%tag(attr=\"\" attr=\"\" ) Content\n```\n\nThe `id` and `class` attributes can also be assigned directly to the tag:\n\n``` haml\n%tag#id.class Content\n```\n\nIf you are creating a div you don't need to include the tag at all. This HAML\n\n``` haml\n#main\n  .blue Content\n```\n\nWill generate the following HTML\n\n``` html\n\u003cdiv id='main'\u003e\n  \u003cdiv class='blue'\u003e\n    Content\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n## Passing Arguments\n\nThe render function will also take a list of named arguments that can be evaluated when compiling the HTML\n\nGiven the following HAML:\n\n``` haml\n#main\n  .blue= content\n```\n\nThen call render and pass in  the `haml` and `content`:\n\n``` elixir\nCalliope.render haml, [content: \"Hello, World\"]\n```\n\nCalliope will render:\n\n``` html\n\u003cdiv id='main'\u003e\n  \u003cdiv class='blue'\u003e\n    Hello, World\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n## Embedded Elixir\n\nCalliope doesn't just evaluate arguments, you can actually embed Elixir directly into the templates:\n\n### for\n\n``` haml\n- for { id, headline, content } \u003c- posts do\n  %h1\n    %a{href: \"posts/#{id}\"}= headline\n  .content\n    = content\n```\n\nPass that to `render` with a list of posts\n\n``` elixir\nCalliope.render haml, [posts: [{1, \"Headline 1\", \"Content 1\"}, {2, \"Headline 2\", \"Content 2\"}]\n```\n\nWill render\n\n``` html\n\u003ch1\u003e\n  \u003ca href=\"/posts/1\"\u003eHeadline 1\u003c/a\u003e\n\u003c/h1\u003e\n\u003cdiv class=\"content\"\u003e\n  Content 1\n\u003c/div\u003e\n\u003ch1\u003e\n  \u003ca href=\"/posts/2\"\u003eHeadline 2\u003c/a\u003e\n\u003c/h1\u003e\n\u003cdiv class=\"content\"\u003e\n  Content 2\n\u003c/div\u003e\n```\n\n### if, else, and unless\n\n``` haml\n- if post do \n  %h1= post.title\n  - if post.comments do\n    %p Has some comments\n  - else\n    %p No Comments\n- unless user_guest(user)\n  %a{href: \"posts/edit/#{id}\"}= Edit\n```\n\n### case\n\n``` haml\n- case example do\n  - \"one\" -\u003e \n    %p Example one\n  - other -\u003e \n    %p Other Example  \n      #{other}\n```\n\n### Local Variables\n\n``` haml\n- answer = 42\n%p= \"What is the answer #{answer}\"\n```\n\n### Anonymous Functions\n\n``` haml\n- form_for @changeset, @action, fn f -\u003e\n  .form-group\n    = label f, :name, \"Name\", class: \"control-label\" \n    = text_input f, :name, class: \"form-control\" \n  .form-group\n    = submit \"Submit\", class: \"btn btn-primary\" \n```\n\n## Precompile Templates\n\nCalliope provides an Engine to precompile your haml templates into functions. This parses the template at compile time and creates a function that takes the name and args needed to render the page. These functions are scoped to the module that uses the engine.\n\nAdding this functionality is easy.\n\n``` elixir\n  defmodule Simple do\n\n    use Calliope.Engine\n\n    def show do\n      content_for(:show, [title: Calliope])\n    end\n\n  end\n```\n\nIf you are using layouts, you can set the layout and call the `content_with_layout` function.\n\n``` elixir\n  defmodule Simple do\n\n    use Calliope.Engine, layout: \"application\"\n\n    def show do\n      content_with_layout(:show, [title: Calliope])\n    end\n\n  end\n```\n\nIn addition to `:layout`, you can also set the following options:\n\n`:path` - provides the root path. The default is the current working directory.\n`:templates` - used to define where the templates are stored. By default it will use `:path`\n`:alias` - used to set the directory where the templates are located. The\n            default value is 'templates'.\n`:layout_directory` - the directory that your layouts are stored relative to the\n             templates path. The default directory is `layouts`\n`:layout` - the layout to use for templates. The default is `:none` or you can pass in\n            the name of a layout.\n\n## Coming Soon\n\n* Rendering partials\n* Exception messages\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnurugger07%2Fcalliope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnurugger07%2Fcalliope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnurugger07%2Fcalliope/lists"}