{"id":15523766,"url":"https://github.com/fntz/sirius","last_synced_at":"2025-04-23T07:22:46.887Z","repository":{"id":17857127,"uuid":"20780989","full_name":"fntz/sirius","owner":"fntz","description":"Modern coffeescript/javascript framework","archived":false,"fork":false,"pushed_at":"2021-03-25T12:38:07.000Z","size":1772,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T20:43:03.104Z","etag":null,"topics":["coffeescript","framework","javascript","jquery","mvc","mvp","mvvm","prototype","sirius","strategy","web"],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fntz.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-12T19:57:01.000Z","updated_at":"2022-03-05T17:12:02.000Z","dependencies_parsed_at":"2022-09-13T08:11:54.740Z","dependency_job_id":null,"html_url":"https://github.com/fntz/sirius","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fsirius","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fsirius/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fsirius/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fntz%2Fsirius/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fntz","download_url":"https://codeload.github.com/fntz/sirius/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250387687,"owners_count":21422182,"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":["coffeescript","framework","javascript","jquery","mvc","mvp","mvvm","prototype","sirius","strategy","web"],"created_at":"2024-10-02T10:46:54.048Z","updated_at":"2025-04-23T07:22:46.857Z","avatar_url":"https://github.com/fntz.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n`Sirius` is a modern coffeescript MVC/MVVM framework for client-side.\n\n[wiki](https://github.com/fntz/sirius/wiki)\n\n[todoapp sources](https://github.com/fntz/sirius/tree/master/todomvc)\n\n### browser support: IE9+, FF, Opera, Chrome\n\n### Features\n\n+ Template free — you may use any template engine or don't use any at all\n+ MVC style\n+ MVVM binding (view to view, model to view, view to model, etc)\n+ Built-in Collections \n+ Built-in Validators\n+ Simple for customization\n+ Works with jQuery, Prototype.js, and Vanillajs\n+ Support html5 routing\n+ Time events in routing\n+ Log all actions in an application [read about](https://github.com/fntz/sirius/wiki/Logger)\n+ And many others\n\n# Install\n\n`npm install sirius` \n\nor download manually [sirius.min.js](https://raw.githubusercontent.com/fntz/sirius/master/sirius.min.js) and [jquery_adapter.min.js](https://raw.githubusercontent.com/fntz/sirius/master/jquery_adapter.min.js) or [prototype_js_adapter.min.js](https://raw.githubusercontent.com/fntz/sirius/master/prototypejs_adapter.min.js) from repo.\n\nor only core part: [sirius-core.min.js](https://raw.githubusercontent.com/fnt/sirius/master/sirius-core.min.js)\n\n#### TODO\n\n1. `grep -r -i -e 'fixme' -e 'todo' src`\n2. more tests\n\n# Usage\n\n### 1. Define controllers\n\n```coffee\nMyController = \n  action: (param) -\u003e\n    # ...\n  \n  run: () -\u003e\n    # ...\n  after_run: () -\u003e\n    # run after `run` method\n    \n  guard_event: (event) -\u003e\n    if condition \n      true \n    else \n      false\n      \n  event_action: (event, id) -\u003e\n    # ...\n\n```\n\n#### 1.1 Advanced with controllers\n\nSometimes you need to share some actions between all controllers - some services/ajax requests, or some like this, that's simple:\n\n```coffee\n\nCommonMethods =\n\n  ajax: (args...) -\u003e\n  on_more_action: (args...) -\u003e\n\n# then\n  Sirius.Application.run\n    route: # you routes\n    adapter: # some adapter\n    controller_wrapper : CommonActions\n\n# and now in you controller:\n\nController =\n  action: (url) =\n    # possible use\n    # any method from CommonActions, like\n    logger.info(\"start ajax request\")\n    response = ajax(url)\n    logger.info(\"stop ajax request, response #{response} given\")\n\n```\n\n##### note: by default Sirius `controller_wrapper` contain only `redirect` action\n\n\n### 2. Define routes\n\n```coffee\n  routes =\n    \"application:run\"   : controller: MyController, action: \"action\"\n    \"/plain\"            : controller: MyController, action: \"plain\"\n    \"#/:title\"          : controller: MyController, action: \"run\"\n    \"every 10s\"         : controller: MyController, action: \"refresh\"\n    \"click #my-element\" : controller: MyController, action: \"event_action\", guard: \"guard_event\", data: \"id\"  \n\n```\n\n[more about routing and controllers](https://github.com/fntz/sirius/wiki/Controllers-and-Routing)\n\n### 3. Define models\n\n```coffee\n  \n  class Person extends Sirius.BaseModel\n     @attrs: [\"id\", \"name\", \"age\"]\n     @comp(\"id_and_name\", \"id\", \"name\") # \u003c- computed field\n     @guid_for: \"id\"\n     @validate:\n       id: only_integers: true\n\n```\n\n[more about models](https://github.com/fntz/sirius/wiki/Models)\n\n### 4. Run Application\n\n```coffee\n  Sirius.Application.run({route: routes, adapter: new YourAdapter()})\n```\n\n[more about application and settings](https://github.com/fntz/sirius/wiki/Application-\u0026-Settings)\n\n### 5. Use Validators\n\n```coffee\n  class Person extends Sirius.BaseModel\n    @attrs: [\"id\", \"name\", \"age\"]\n    @guid_for: \"id\"\n    @form_name: \"my-person-form\"\n    @validate :\n      name:\n        presence: true\n        format: with: /^[A-Z].+/\n        length: min: 3, max: 7\n        exclusion: [\"title\"]\n```\n\n#### 5.1 Define custom Validator\n\n```coffee\n  class MyValidator extends Sirius.Validator\n    validate: (value, attrs) -\u003e\n      if value.length == 3\n        @msg = \"Error, value should have length 3\"\n        false\n      else\n        true\n\n# register validator\nSirius.BaseModel.register_validator(\"my_validator\", MyValidator)\n\n# and use\n  class MyModel extends Sirius.BaseModel\n    @attrs: [\"title\"]\n    @validate:\n      title:\n        my_validator: some_attribute: true\n\n```\n\n[more about validators](https://github.com/fntz/sirius/wiki/Validators)\n\n### 6. Views\n\nIn Sirius, views are an element on the page. You might bind view and other views, or model.\n\n```coffee\n  view = new Sirius.View(\"#id\", (x) -\u003e \"#{x}!!!\")\n  view.render(\"new content\").swap()\n  # then in html \u003celement id='id'\u003enew content!!!\u003c/element\u003e\n```\n\n`swap` - this strategy, how to work with content. Support: `swap`, `append`, `prepend` stretegies.\n\nDefine own strategy:\n\n```coffee\n Sirius.View.register_strategy('html',\n    transform: (oldvalue, newvalue) -\u003e \"\u003cb\u003e#{newvalue}\u003cb\u003e\"\n    render: (adapter, element, result, attribute) -\u003e\n      if attribute == 'text'\n        $(element).html(result)\n      else\n        throw new Error(\"Html strategy work only for text, not for #{attribute}\")\n )\n\n# use it\n\nview = new Sirius.View(\"#element\")\nview.render(\"some text\").html()\n\n# then in html\n\n\u003cspan id='element'\u003e\u003cb\u003esome text\u003c/b\u003e\u003c/span\u003e\n```\n\nAlso you want to swap content for any attribute:\n\n```coffee\nview.render(\"active\").swap('class')\n```\n\n[more about views](https://github.com/fntz/sirius/wiki/Views)\n\n### 7. Use collections\n\n```coffee\npersons = new Sirius.Collection(Person, {index: ['name']})\njoe = new Person({\"name\": \"Joe\", \"age\" : 25})\n\npersons.add(joe)\n\nperson.find(\"name\", \"Joe\").to_json() # =\u003e {\"id\" : \"g-u-i-d\", \"name\" : \"Joe\", \"age\" : 25}\n```\n\n[more about collections](https://github.com/fntz/sirius/wiki/Collections)\n\n### 8. Binding (Materialization)\n\nSupported binding: \n    1. view to model\n    2. view to view \n    3. model to view\n    4. or model|view to function. \n\n#### View To Model\n\n```coffee\n# view \n\u003cdiv id=\"my-input\"\u003e\n  \u003cinput type=\"text\" /\u003e\n\u003c/div\u003e\n\n# model\nclass MyModel extends Sirius.BaseModel\n  @attrs: [\"id\", \"name\"]\n \nmodel = new MyModel()\nview = new Sirius.View(\"#my-input\")\n\n# and now materialize!\nMaterializer.build(view, model) # from view to model\n  .field((v) -\u003e v.zoom(\"input\"))\n  .to((m) -\u003e m.name)          # or just .to('name')\n  .transform((result) -\u003e \"#{result.text}!\")\n  .run()   \n    \n```\n\n#### View To View\n```coffee\n\n# view1 \n\u003cdiv id=\"element\"\u003e\n  \u003cp\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n# view2\n\u003cdiv id=\"my-input\"\u003e\n  \u003cinput type=\"text\" /\u003e\n\u003c/div\u003e\n\nview1 = new Sirius.View(\"#element\")\nview2 = new Sirius.View(\"#my-input\")\n\nSirius.Materializer.build(view2, view1) # from view2 to view1 \n  .field(\"input\") # or field((view) -\u003e view.zoom(\"input\"))\n  .to('p')        # the same ^\n  .handle((view, result) -\u003e             # you can define own handler\n    view.render(result.text).swap()     # default  \n  ) \n  .run()\n\n```\n\n#### Model to View \n\n```coffee\n# model\nclass MyModel extends Sirius.BaseModel\n  @attrs: [\"name\"]\n  @validate:\n    name:\n      length: min: 3, max: 10\n\n# view\n\u003cdiv id=\"view\"\u003e\n  \u003cdiv class=\"model-name\"\u003e\u003c/div\u003e\n  \u003cspan class=\"model-errors\"\u003e\u003c/span\u003e\n\u003c/div\u003e\n\nmodel = new MyModel()\nview = new Sirius.View(\"#view\")\n\nSirius.Materializer.build(model, view)\n  .field((m) -\u003e m.name)\n  .to('.model-name')\n  .field((m) -\u003e m.errors.name.length) # path to validator\n  .to('.model-errors')\n  .run()\n\n```\n\n\n[more about binding](https://github.com/fntz/sirius/wiki/Binding)\n\n### 9. Logger\n\nuse as: \n```\nMainController = \n  logger: Sirius.Application.get_logger(\"MainController\")\n  action: () -\u003e\n    @logger.info(\"test\")  \n```\n[more](https://github.com/fntz/sirius/wiki/Logger)\n\n# run todo app\n\n1. install deps for todo app with `rake todo:install`\n\n2. compile: `rake todo:compile`\n\n3. run: `rake todo:run`\n\n4. open browser: `http://localhost:4567/` \n\n\n# More info\n\n+ [TodoMVC Application](https://github.com/fntz/sirius/tree/master/todomvc)\n\n# Tasks\n\nUse `rake` for run task. Before work run `rake install` for installing dependencies.\n\n`rake install` - install all dependencies\n\n`rake doc` - generate project documentation\n\n`rake build` - compile coffeescript into javascript file\n\n`rake test` - complile fixtures for tests, and run server\n\n`rake minify` - use [yuicompressor](https://github.com/yui/yuicompressor) for minify files\n\n# Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n\n\n\n\n### LICENSE : MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffntz%2Fsirius","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffntz%2Fsirius","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffntz%2Fsirius/lists"}