{"action":"created","comment":{"url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/comments/48394296","id":48394296,"diff_hunk":"@@ -0,0 +1,250 @@\n+---\n+title: Lotus - Guides - Assets Overview\n+---\n+\n+# Assets\n+\n+Lotus supports powerful features for web assets.\n+\n+## Configuration\n+\n+Each application can have its own separated assets settings in application configuration.\n+\n+### Compile Mode\n+\n+Toggle this value, to determine if the application must preprocess or copy assets from sources to public directory.\n+It's turned on by default in _development_ and _test_ environments, but turned off for _production_.\n+\n+```ruby\n+# apps/web/application.rb\n+module Web\n+  class Application < Lotus::Application\n+    configure do\n+      # ...\n+      assets do\n+        # compile true, enabled by default\n+      end\n+    end\n+\n+    configure :production do\n+      compile false\n+    end\n+  end\n+end\n+```\n+\n+### Digest Mode\n+\n+In order to force browsers to cache the right copy of an asset, during the deploy, Lotus creates a copy of each file by [appending its checksum](/guides/command-line/assets) to the file name.\n+\n+We can control this feature via application configuration.\n+It's turned on by default only in _production_ environment.\n+\n+```ruby\n+# apps/web/application.rb\n+module Web\n+  class Application < Lotus::Application\n+    configure do\n+      # ...\n+      assets do\n+        # digest false, disabled by default\n+      end\n+    end\n+\n+    configure :production do\n+      digest true\n+    end\n+  end\n+end\n+```\n+\n+If enabled, [assets helpers](/guides/helpers/assets) will generate checksum relative URLs.\n+\n+```erb\n+<%= javascript 'application' %>\n+```\n+\n+```html\n+<script src=\"/assets/application-d1829dc353b734e3adc24855693b70f9.js\" type=\"text/javascript\"></script>\n+```\n+\n+## Serve Static Assets\n+\n+It can dinamically serve them during development.\n+It mounts `Lotus::Static` middleware in project Rack stack. This this component is conditionally activated, if the environment variable `SERVE_STATIC_ASSETS` equals to `true`.\n+\n+By default, new projects are generated with this feature enabled in _development_ and _test_ mode, via their corresponding `.env.*` files.\n+\n+```\n+# .env.development\n+# ...\n+SERVE_STATIC_ASSETS=\"true\"\n+```\n+\n+Lotus assumes that projects in _production_ mode are deployed using a web server like Nginx that is responsible to serve them without even hitting the Ruby code.\n+\n+<p class=\"convention\">\n+  Static assets serving is enabled by default in <em>development</em> and <em>test</em> environments, but turned off for <em>production</em>.\n+</p>\n+\n+There are cases where this assumption isn't true. For instance, Heroku requires Ruby web apps to serve static assets.\n+To enable this feature in production, just make sure that this special environment variable is set to `true` (in `.env` or `.env.production`).\n+\n+### What Does It Mean To Serve Static Assets With Lotus?\n+\n+As mentioned above, when this feature is enabled, a special middleware is added in front of the project Rack stack: `Lotus::Static`.\n+\n+Incoming requests can generate the following use cases\n+\n+#### Fresh Asset\n+\n+```\n+GET /assets/application.js\n+```\n+\n+It copies the `apps/web/assets/javascripts/application.js` to `public/assets/application.js` and then serves it.\n+\n+<p class=\"notice\">\n+  Assets are copied only if the destination path is NOT existing (eg. <code>public/assets/application.js</code>).\n+  If it DOES exist, the asset is only served, without copying it.\n+</p>\n+\n+<p class=\"warning\">\n+  When an application has turned OFF assets compilation (Compile mode), Lotus won't copy the file.\n+</p>\n+\n+#### Stale Asset\n+\n+This could happen in _development_ mode, when we require an asset the first time, it's get copied over `public/`, then we edit it, so the destination file is stale.\n+\n+```\n+GET /assets/application.js\n+# edit the original file: apps/web/assets/javascripts/application.js\n+# then require it again\n+GET /assets/application.js\n+```\n+\n+It copies **again** the source into the destination file (`public/assets/application.js`) and then serves it.\n+\n+#### Precompiled Asset\n+\n+Let's say we use Sass to write our stylesheets.\n+\n+```\n+GET /assets/application.css\n+```\n+\n+It preprocess the `apps/web/assets/stylesheet/application.css.sass` to `public/assets/application.css` and then serves it.\n+\n+#### Dynamic Resource\n+\n+```\n+GET /books/23\n+```\n+\n+This isn't a static file available under `public/`, so the control passes to the backend that hits the appropriate action.\n+\n+#### Missing Resource\n+\n+```\n+GET /unknown\n+```\n+\n+This isn't a static file or a dynamic resource, the project returns a `404 (Not Found)`.\n+\n+## Sources\n+\n+Each application has a separated set of directories where to look up for files.\n+Assets are recursively searched under these paths.\n+\n+New projects have a default directory where to put application assets:\n+\n+```\n+% tree apps/web/assets\n+apps/web/assets\n+├── favicon.ico\n+├── images\n+├── javascripts\n+└── stylesheets\n+\n+3 directories, 1 file\n+```\n+\n+We can add as many directories we want under it (eg. `apps/web/assets/fonts`).\n+\n+<p class=\"convention\">\n+  For a given application named <code>Web</code>, the default assets source is <code>apps/web/assets</code>\n+</p>\n+\n+### Adding Sources\n+\n+If we want add other sources for a given application, we can specify them in the configuration.\n+\n+```ruby\n+# apps/web/application.rb\n+module Web\n+  class Application < Lotus::Application\n+    configure do\n+      # ...\n+      assets do\n+        # apps/web/assets is added by default\n+        sources << [\n+          'vendor/assets'\n+        ]\n+      end\n+    end\n+  end\n+end\n+```\n+\n+This will add `apps/web/vendor/assets` and all its subdirectories.\n+\n+<p class=\"warning\">\n+Lotus looks recursively to the assets sources. In order to NOT accidentally disclose sensitive files like secrets or source code, please make sure that these sources directories ONLY contain web assets.\n+</p>\n+\n+## Third Party Gems\n+\n+Lotus allows to use [Rubygems](https://rubygems.org) as a way to distribute web assets and make them available to Lotus applications.\n+\n+Third party gems can be maintained by developers who want to bring frontent frameworks support to Lotus.","path":"source/guides/assets/overview.md","position":210,"original_position":210,"commit_id":"d490d4fbc321130c1d20d21342f20449d485b541","original_commit_id":"d490d4fbc321130c1d20d21342f20449d485b541","user":{"login":"joneslee85","id":135605,"avatar_url":"https://avatars.githubusercontent.com/u/135605?v=3","gravatar_id":"","url":"https://api.github.com/users/joneslee85","html_url":"https://github.com/joneslee85","followers_url":"https://api.github.com/users/joneslee85/followers","following_url":"https://api.github.com/users/joneslee85/following{/other_user}","gists_url":"https://api.github.com/users/joneslee85/gists{/gist_id}","starred_url":"https://api.github.com/users/joneslee85/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joneslee85/subscriptions","organizations_url":"https://api.github.com/users/joneslee85/orgs","repos_url":"https://api.github.com/users/joneslee85/repos","events_url":"https://api.github.com/users/joneslee85/events{/privacy}","received_events_url":"https://api.github.com/users/joneslee85/received_events","type":"User","site_admin":false},"body":"s/frontent/frontend","created_at":"2015-12-24T03:35:03Z","updated_at":"2015-12-24T03:35:03Z","html_url":"https://github.com/lotus/lotus.github.io/pull/114#discussion_r48394296","pull_request_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114","_links":{"self":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/comments/48394296"},"html":{"href":"https://github.com/lotus/lotus.github.io/pull/114#discussion_r48394296"},"pull_request":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114"}}},"pull_request":{"url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114","id":54491447,"html_url":"https://github.com/lotus/lotus.github.io/pull/114","diff_url":"https://github.com/lotus/lotus.github.io/pull/114.diff","patch_url":"https://github.com/lotus/lotus.github.io/pull/114.patch","issue_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/114","number":114,"state":"open","locked":false,"title":"Prepare for v0.6.0","user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"body":"**PLEASE DON'T MERGE UNTIL v0.6.0 WILL BE RELEASED.**\r\n\r\n---\r\n\r\nUpdated guides, upgrade notes, and blog post (not written yet).","created_at":"2015-12-23T17:44:05Z","updated_at":"2015-12-24T03:35:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db7a664e546e12983239daaeb855a3845de9cf4e","assignee":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114/commits","review_comments_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114/comments","review_comment_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/114/comments","statuses_url":"https://api.github.com/repos/lotus/lotus.github.io/statuses/d490d4fbc321130c1d20d21342f20449d485b541","head":{"label":"lotus:release-060","ref":"release-060","sha":"d490d4fbc321130c1d20d21342f20449d485b541","user":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"repo":{"id":15563290,"name":"lotus.github.io","full_name":"lotus/lotus.github.io","owner":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lotus/lotus.github.io","description":"Home page","fork":false,"url":"https://api.github.com/repos/lotus/lotus.github.io","forks_url":"https://api.github.com/repos/lotus/lotus.github.io/forks","keys_url":"https://api.github.com/repos/lotus/lotus.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lotus/lotus.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lotus/lotus.github.io/teams","hooks_url":"https://api.github.com/repos/lotus/lotus.github.io/hooks","issue_events_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/lotus/lotus.github.io/events","assignees_url":"https://api.github.com/repos/lotus/lotus.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/lotus/lotus.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/lotus/lotus.github.io/tags","blobs_url":"https://api.github.com/repos/lotus/lotus.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lotus/lotus.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lotus/lotus.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/lotus/lotus.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lotus/lotus.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/lotus/lotus.github.io/languages","stargazers_url":"https://api.github.com/repos/lotus/lotus.github.io/stargazers","contributors_url":"https://api.github.com/repos/lotus/lotus.github.io/contributors","subscribers_url":"https://api.github.com/repos/lotus/lotus.github.io/subscribers","subscription_url":"https://api.github.com/repos/lotus/lotus.github.io/subscription","commits_url":"https://api.github.com/repos/lotus/lotus.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/lotus/lotus.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/lotus/lotus.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/lotus/lotus.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/lotus/lotus.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lotus/lotus.github.io/merges","archive_url":"https://api.github.com/repos/lotus/lotus.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lotus/lotus.github.io/downloads","issues_url":"https://api.github.com/repos/lotus/lotus.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/lotus/lotus.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/lotus/lotus.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lotus/lotus.github.io/labels{/name}","releases_url":"https://api.github.com/repos/lotus/lotus.github.io/releases{/id}","created_at":"2014-01-01T11:16:40Z","updated_at":"2015-12-17T23:33:48Z","pushed_at":"2015-12-23T17:44:06Z","git_url":"git://github.com/lotus/lotus.github.io.git","ssh_url":"git@github.com:lotus/lotus.github.io.git","clone_url":"https://github.com/lotus/lotus.github.io.git","svn_url":"https://github.com/lotus/lotus.github.io","homepage":"http://lotusrb.org","size":9288,"stargazers_count":44,"watchers_count":44,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":66,"mirror_url":null,"open_issues_count":6,"forks":66,"open_issues":6,"watchers":44,"default_branch":"build"}},"base":{"label":"lotus:build","ref":"build","sha":"2016461b4d73bc2a07fb27bd7bc07983620d2dd2","user":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"repo":{"id":15563290,"name":"lotus.github.io","full_name":"lotus/lotus.github.io","owner":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lotus/lotus.github.io","description":"Home page","fork":false,"url":"https://api.github.com/repos/lotus/lotus.github.io","forks_url":"https://api.github.com/repos/lotus/lotus.github.io/forks","keys_url":"https://api.github.com/repos/lotus/lotus.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lotus/lotus.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lotus/lotus.github.io/teams","hooks_url":"https://api.github.com/repos/lotus/lotus.github.io/hooks","issue_events_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/lotus/lotus.github.io/events","assignees_url":"https://api.github.com/repos/lotus/lotus.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/lotus/lotus.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/lotus/lotus.github.io/tags","blobs_url":"https://api.github.com/repos/lotus/lotus.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lotus/lotus.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lotus/lotus.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/lotus/lotus.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lotus/lotus.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/lotus/lotus.github.io/languages","stargazers_url":"https://api.github.com/repos/lotus/lotus.github.io/stargazers","contributors_url":"https://api.github.com/repos/lotus/lotus.github.io/contributors","subscribers_url":"https://api.github.com/repos/lotus/lotus.github.io/subscribers","subscription_url":"https://api.github.com/repos/lotus/lotus.github.io/subscription","commits_url":"https://api.github.com/repos/lotus/lotus.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/lotus/lotus.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/lotus/lotus.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/lotus/lotus.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/lotus/lotus.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/lotus/lotus.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lotus/lotus.github.io/merges","archive_url":"https://api.github.com/repos/lotus/lotus.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lotus/lotus.github.io/downloads","issues_url":"https://api.github.com/repos/lotus/lotus.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/lotus/lotus.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/lotus/lotus.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/lotus/lotus.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lotus/lotus.github.io/labels{/name}","releases_url":"https://api.github.com/repos/lotus/lotus.github.io/releases{/id}","created_at":"2014-01-01T11:16:40Z","updated_at":"2015-12-17T23:33:48Z","pushed_at":"2015-12-23T17:44:06Z","git_url":"git://github.com/lotus/lotus.github.io.git","ssh_url":"git@github.com:lotus/lotus.github.io.git","clone_url":"https://github.com/lotus/lotus.github.io.git","svn_url":"https://github.com/lotus/lotus.github.io","homepage":"http://lotusrb.org","size":9288,"stargazers_count":44,"watchers_count":44,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":66,"mirror_url":null,"open_issues_count":6,"forks":66,"open_issues":6,"watchers":44,"default_branch":"build"}},"_links":{"self":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114"},"html":{"href":"https://github.com/lotus/lotus.github.io/pull/114"},"issue":{"href":"https://api.github.com/repos/lotus/lotus.github.io/issues/114"},"comments":{"href":"https://api.github.com/repos/lotus/lotus.github.io/issues/114/comments"},"review_comments":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114/comments"},"review_comment":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lotus/lotus.github.io/pulls/114/commits"},"statuses":{"href":"https://api.github.com/repos/lotus/lotus.github.io/statuses/d490d4fbc321130c1d20d21342f20449d485b541"}}}}