This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bootstrapAngular = -> | |
$('[ng-app]').each -> | |
module = $(this).attr('ng-app') | |
angular.bootstrap(this, [module]) | |
$(document).on('page:load', bootstrapAngular) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(scope, elem, attrs) -> | |
id = _.uniqueId() | |
elem.attr('endless-page-elem-id', id) | |
$(window).on 'scroll', -> | |
return if $("[endless-page-elem-id='#{id}']").length is 0 | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddHstoreExtension < ActiveRecord::Migration | |
def up | |
enable_extension 'hstore' | |
end | |
def down | |
disable_extension 'hstore' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module = angular.module(...) | |
module.config ($httpProvider) -> | |
authToken = $('meta[name="csrf-token"]').attr('content') | |
$httpProvider.defaults.headers.common['X-CSRF-TOKEN'] = authToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module = angular.module(...) | |
module.config ($httpProvider, $provide) -> | |
$httpProvider.defaults.headers.patch = {'Content-Type': 'application/json'} | |
$provide.decorator '$http', ($delegate) -> | |
$delegate.patch = (url, config) -> | |
$delegate(angular.extend(config or {}, method: 'patch', url: url)) | |
$delegate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomSlimEngine < Slim::Template | |
def evaluate(scope, locals, &block) | |
scope.class_eval do | |
include Rails.application.routes.url_helpers | |
include Rails.application.routes.mounted_helpers | |
include ActionView::Helpers | |
end | |
super | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack/rewrite' | |
Rails.application.config.middleware.insert(0, Rack::Rewrite) do | |
rewrite %r{^/(?!assets|auth|admin)}, '/' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
namespace :assets do | |
Rake::Task['deploy:assets:precompile'].clear_actions | |
desc "Precompile assets on local machine and upload them to the server." | |
task :precompile do | |
run_locally do | |
execute 'RAILS_ENV=production bundle exec rake assets:precompile' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.config.assets.precompile += %w( ratchicons.eot | |
ratchicons.woff | |
ratchicons.ttf | |
ratchicons.svg ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 不考慮重複 key 和無 value 的情況 | |
parseQS = (qs = location.search) -> | |
object = {} | |
pairs = qs.substring(1) # 去除前置 ? 字元 | |
.split('&') # 變成一堆 oo=xx 字串 | |
for pair in pairs | |
[key, value] = pair.split('=') | |
object[key] = value |