{"id":13880457,"url":"https://github.com/andreapavoni/panoramic","last_synced_at":"2025-04-07T13:08:57.971Z","repository":{"id":677162,"uuid":"1864747","full_name":"andreapavoni/panoramic","owner":"andreapavoni","description":"store rails views on database instead of filesystem","archived":false,"fork":false,"pushed_at":"2024-05-31T08:16:49.000Z","size":86,"stargazers_count":171,"open_issues_count":10,"forks_count":63,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T11:06:55.935Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/andreapavoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-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":"2011-06-08T10:43:37.000Z","updated_at":"2025-02-11T15:17:51.000Z","dependencies_parsed_at":"2024-06-18T18:22:20.538Z","dependency_job_id":null,"html_url":"https://github.com/andreapavoni/panoramic","commit_stats":{"total_commits":51,"total_committers":15,"mean_commits":3.4,"dds":0.6666666666666667,"last_synced_commit":"bd766f61f32e5fcf3c050f56f6e16d49a169d025"},"previous_names":["apeacox/panoramic"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreapavoni%2Fpanoramic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreapavoni%2Fpanoramic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreapavoni%2Fpanoramic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreapavoni%2Fpanoramic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreapavoni","download_url":"https://codeload.github.com/andreapavoni/panoramic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"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-06T08:03:03.109Z","updated_at":"2025-04-07T13:08:57.949Z","avatar_url":"https://github.com/andreapavoni.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Panoramic [![Build Status](https://secure.travis-ci.org/apeacox/panoramic.png)](http://travis-ci.org/apeacox/panoramic)\nAn [ActionView::Resolver] implementation to store rails views (layouts, templates and partials) on database. Simply put: what you can do with views on filesystem, can be done on database.\n\n**NOTE:** at the moment, only ActiveRecord is supported, I've planned to add more ORMs (see Todo). If you can't wait, adding other ORMs should be very trivial.\n\n## Installation\nAdd the following line to Gemfile:\n\n```ruby\ngem \"panoramic\"\n```\n\n## Usage\n\n### Mandatory fields\nYour model should have the following fields:\n\n* body (text): the source of template\n* path (string): where to find template (ex: layouts/application,\n  you_controller/action, etc...)\n* locale (string): it depends from available locales in your app\n* handler (string): as locale field, it depends from avaiable handlers\n  (erb, haml, etc...)\n* partial (boolean): determines if it's a partial or not (false by\n  default)\n* format (string): A valid mimetype from Mime::SET.symbols\n\nthey're what the rails' Resolver API needs to lookup templates.\n\n### Model\nA simple macro in model will activate your new Resolver. You can use a dedicated model to manage all the views in your app, or just for specific needs (ex: you want a custom template for some static pages, the other views will be fetched from filesystem).\n\n```ruby\nclass TemplateStorage \u003c ActiveRecord::Base\n  store_templates\nend\n```\n\n### Controller\nTo add Panoramic::Resolver in controller, depending on your needs, you may choose:\n\n* [prepend_view_path]: search for templates *first* in your resolver, *then* on filesystem\n* [append_view_path]: search for templates *first* on filesystem, *then* in your resolver\n\n**NOTE**: the above methods are both class and instance methods.\n\n\n```ruby\nclass SomeController \u003c ApplicationController\n  prepend_view_path TemplateStorage.resolver\n\n  def index\n    # as you may already know, rails will serve 'some/index' template by default, but it doesn't care where it is stored.\n  end\n\n  def show\n    # explicit render\n    render :template =\u003e 'custom_template'\n  end\n\n  def custom_template\n    # use another model to fetch templates\n    prepend_view_path AnotherModel.resolver\n  end\nend\n```\n\nAnd let's say you want to use database template resolving in all your controllers, but\nwant to use panoramic only for certain paths (prefixed with X) you can use\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  prepend_view_path TemplateStorage.resolver(:only =\u003e 'use_this_prefix_only')\nend\n```\n\nThis helps reducing the number of database requests, if Rails for example tries to look\nfor layouts per controller.\n\n### ActionMailer\n\n```ruby\nclass MyEmail \u003c ActionMailer::Base\n  prepend_view_path TemplateStorage.resolver\n```\nUsing prepend_view_path/append_view_path you are stuck to the current context (e.g. the method calling \"mail\").\nIf you want to dynamically change the path depending on a certain variable, call the prepend_view_path/append_view_path inside the method's context with an additional path variable.\nThis could be useful, if you want to use only one method for sending different templates depending on the template.path .\n\n```ruby\nclass MyEmail \u003c ActionMailer::Base\n\n  def method_that_sets_resolver_path\n    prepend_view_path TemplateStorage.resolver(:path =\u003e model.path)\n  end\n```\n\n## Documentation\nNeed more help? Check out ```spec/dummy/```, you'll find a *dummy* rails app I used to make tests ;-)\n\n## Testing\nEnter Panoramic gem path, run ```bundle install``` to install development and test dependencies, then ```rake spec```.\n\n\n## Todo\n\n### Long term\n* add generators\n\n## Contributing\nFork, make your changes, then send a pull request.\n\n## Credits\nThe main idea was *heavily inspired* from José Valim's awesome book [Crafting Rails Applications]. It helped me to better understand some Rails internals.\n\n[ActionView::Resolver]: http://api.rubyonrails.org/classes/ActionView/Resolver.html\n[append_view_path]: http://apidock.com/rails/AbstractController/ViewPaths/ClassMethods/append_view_path\n[prepend_view_path]: http://apidock.com/rails/AbstractController/ViewPaths/ClassMethods/prepend_view_path\n[Crafting Rails Applications]: http://pragprog.com/titles/jvrails/crafting-rails-applications\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreapavoni%2Fpanoramic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreapavoni%2Fpanoramic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreapavoni%2Fpanoramic/lists"}