{"id":19723605,"url":"https://github.com/nitrogen/sample_nitrogen_plugin","last_synced_at":"2025-04-29T22:31:01.199Z","repository":{"id":66535685,"uuid":"12441851","full_name":"nitrogen/sample_nitrogen_plugin","owner":"nitrogen","description":"A Sample Plugin for Nitrogen's Plugin System","archived":false,"fork":false,"pushed_at":"2013-10-26T19:20:52.000Z","size":95,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T20:03:28.219Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nitrogen.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-28T18:49:23.000Z","updated_at":"2014-12-07T23:04:44.000Z","dependencies_parsed_at":"2023-02-20T07:30:24.167Z","dependency_job_id":null,"html_url":"https://github.com/nitrogen/sample_nitrogen_plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrogen%2Fsample_nitrogen_plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrogen%2Fsample_nitrogen_plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrogen%2Fsample_nitrogen_plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrogen%2Fsample_nitrogen_plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitrogen","download_url":"https://codeload.github.com/nitrogen/sample_nitrogen_plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251592959,"owners_count":21614449,"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-11-11T23:22:52.227Z","updated_at":"2025-04-29T22:31:00.622Z","avatar_url":"https://github.com/nitrogen.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sample Nitrogen Plugin\n\nThis is a basic skeleton of a plugin for the [Nitrogen Web\nFramework](http://nitrogenproject.com), which introduced a plugin system in\nversion 2.2.0.\n\nThere is some general documentation on working with Nitrogen plugins in the\n[Nitrogen Documentation](http://nitrogenproject.com/doc/plugins.html).\n\nThis, however, is more specific to creating an effective Nitrogn plugin for\nreuse in your systems and others.\n\n## Introduction\n\nNitrogen plugins are Erlang applications formatted in a certain way, and can be\nset up as rebar dependencies. As long as the application is a valid rebar\ndependency, and has a file called nitrogen.plugin in the root of the directory,\nthen it'll be treated as a plugin by the standard Nitrogen Makefile.\n\nMost Nitrogen plugins will be custom Nitrogen elements, though they can be as\nsimple or as elaborate as needed, including adding dependency services and\napplications.\n\n## Adding a Nitrogen Plugin to Your Nitrogen App (post 2.2.0)\n\nModify your rebar.config file and add to the `deps` section the following:\n\n```erlang\n{my_plugin, \".*\", {git, \"git://github.com/nitrogen/sample_nitrogen_plugin.git\", {branch, master}}}\n```\n\nThen run `make` in your application.\n\nThis will do the following:\n  + Download the plugin source and add it as a dependency.\n  + Import any of the contents of the plugin's `include/` directory, linking to\n    each found .hrl file in the application's `plugins.hrl` file.\n  + Copy (or symlink) the contents of the plugin's `static/` directory.\n  + Recompile the application's source code\n\n## Tree Structure\n\nThe basic tree structure of a Nitrogen plugin is as follows:\n\n```\n.\n├── ebin\n├── include\n│   └── records.hrl\n├── nitrogen.plugin\n├── priv\n│   └── static\n│       ├── css\n│       │   └── style.css\n│       ├── images\n│       └── js\n│           └── plugin.js\n└── src\n    ├── element_sample_nitrogen_plugin.erl\n    └── sample_nitrogen_plugin.app.src\n```\n\n### ebin/\n\nThis is the standard target for the compiled Erlang .beam files (and the .app\nfile generated from the .app.src file)\n\n### include/\n\nThis will be where you will have any include files. Any .hrl files found in\nhere will be automatically referenced by the Nitrogen `do-plugins` script, and\nimported into each page in your application.\n\n### include/records.hrl\n\nThis will be your record definitions. For example:\n\n```erlang\n-record(sample_nitrogen_plugin, {?ELEMENT_BASE(element_sample_nitrogen_plugin), field1, field2 }).\n```\n\nNote, that we do not need to add `-include_lib(\"nitrogen_core/include/wf.hrl)`\nto this because that will be included in each page anyway.\n\n### src/\n\nLike any good Erlang app, this will be where you put your Erlang module source\nfiles, such as your element rendering modules.  Additionally, the .app.src file\nwill typically go here.\n\nAn element rendering module should look something like this:\n\n```erlang\n-module (element_sample_nitrogen_plugin).\n-include_lib(\"nitrogen_core/include/wf.hrl\").\n-include(\"records.hrl\").\n\n-export([\n    reflect/0,\n    render_element/1\n]).\n\nreflect() -\u003e record_info(fields, sample_nitrogen_plugin).\n\nrender_element(_Rec = #sample_nitrogen_plugin{}) -\u003e\n    [\n        \u003c\u003c\"Hello! This is a sample Nitrogen Plugin\"\u003e\u003e\n    ].\n```\n\n**A few things about includes:**\n\n  + `-include_lib(\"nitrogen_core/include/wf.hrl\").` Should still exist to\n    import all Nitrogen elements.\n  + `-include(\"records.hrl\").` This is actually pointing at the `records.hrl`\n    file found in the *plugin's* directory, not the general `records.hrl` file\nin your application's directory.\n\n### priv/static/\n\nThis will be the location of static resources: images, javascript files,\nstylesheets, or anything else for that matter.\n\nThe contents of this directory will be either copied (or symlinked) into\nstatic/plugins/plugin_name\n\n## Read More\n\nRead about [Nitrogen Plugins](http://nitrogenproject.com/doc/plugins.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrogen%2Fsample_nitrogen_plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitrogen%2Fsample_nitrogen_plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrogen%2Fsample_nitrogen_plugin/lists"}