Skip to content

Commit

Permalink
Dump angular rails templates in favor of home grown - see pitr/angula…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Rogers committed May 30, 2018
1 parent c103166 commit 0882ee7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -4,7 +4,6 @@ ruby '2.5.1'

gem 'actionmailer-text'
gem 'active_model_serializers'
gem 'angular-rails-templates'
gem 'authlogic'
gem 'autoprefixer-rails'
gem 'aws-sdk', '~> 2.4.x'
Expand All @@ -30,6 +29,7 @@ gem 'hashie'
gem 'htmlentities'
gem 'jbuilder' # non-html output (rss, atom)
gem 'jquery-rails'
gem 'listen'
gem 'lograge'
gem 'mime-types'
gem 'mojo_magick'
Expand Down
6 changes: 1 addition & 5 deletions Gemfile.lock
Expand Up @@ -58,10 +58,6 @@ GEM
public_suffix (>= 2.0.2, < 4.0)
airbrussh (1.3.0)
sshkit (>= 1.6.1, != 1.7.0)
angular-rails-templates (1.0.2)
railties (>= 4.2, < 6)
sprockets (>= 3.0, < 5)
tilt
ansi (1.5.0)
arel (8.0.0)
ast (2.3.0)
Expand Down Expand Up @@ -555,7 +551,6 @@ PLATFORMS
DEPENDENCIES
actionmailer-text
active_model_serializers
angular-rails-templates
authlogic
autoprefixer-rails
awesome_print
Expand Down Expand Up @@ -600,6 +595,7 @@ DEPENDENCIES
jquery-rails
jslint_on_rails
launchy
listen
lograge
mime-types
mojo_magick
Expand Down
10 changes: 6 additions & 4 deletions app/assets/components/art_pieces_browser/index.html.slim
Expand Up @@ -50,10 +50,12 @@
medium medium-id="{{artPiece.medium.id}}" medium-slug="{{artPiece.medium.slug}}" medium-name="{{artPiece.medium.name}}"
.desc__item.ngwrapper ng-if="hasTags()"
h4.art-piece__info-title Tags
.tags
span ng-repeat='tag in artPiece.tags' repeater-delimiter=','
art-piece-tag tag="tag"
'
#vue-app
.tags
span ng-repeat='tag in artPiece.tags' repeater-delimiter=','
hello
art-piece-tag tag="tag"
'
.push
.social-buttons
.share Share
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -3,7 +3,6 @@
//= require lodash
//= require moment
//= require angular
//= require angular-rails-templates
//= require angular_modules
//= require angular-resource
//= require angular-sanitize
Expand All @@ -14,6 +13,7 @@
//= require re-tree
//= require ng-device-detector
//= require ngDialog
//= require templates
//= require_tree ../components
//= require angularSlideables
//= require mau_app
Expand Down
36 changes: 36 additions & 0 deletions app/assets/javascripts/templates.js.erb
@@ -0,0 +1,36 @@
(function(){
'use strict';

angular.module('templates', []).run(['$templateCache', function($templateCache) {
<%=

environment.context_class.instance_eval { include ActionView::Helpers::JavaScriptHelper }

def put_template_cache_js_command(key, html)
"$templateCache.put(\"#{key}\", \"#{escape_javascript(html)}\");"
end
base_dir = Rails.root.join(*%w(app assets components)).to_s + "/"
handle_slim_file = Proc.new do |file|
key = file.gsub(%r(^#{base_dir}), '').gsub(/.slim$/,'')
html = Slim::Template.new(file, {}).render(self).squish
put_template_cache_js_command(key, html)
end
handle_html_file = Proc.new do |file|
key = file.gsub(%r(^#{base_dir}), '')
html = File.read(file).squish
put_template_cache_js_command(key, html)
end
templates = File.join(base_dir, %w{** *.html})
slim_templates = File.join(base_dir, %w{** *.html.slim})
begin
Dir.glob(templates).map(&handle_html_file) +
Dir.glob(slim_templates).map(&handle_slim_file)
end.join("\n");
%>
}]);
}());
17 changes: 11 additions & 6 deletions config/initializers/angular_rails_templates.rb
@@ -1,9 +1,14 @@
# frozen_string_literal: true

Mau::Application.configure do
# config.angular_templates.module_name = 'templates'
# config.angular_templates.ignore_prefix = %w(templates/)
# config.angular_templates.inside_paths = [Rails.root.join('app', 'assets')]
# config.angular_templates.htmlcompressor = false
config.angular_templates.markups = %w[erb slim]
require 'fileutils'

if Rails.env.development?
cache_path = Rails.root.join('tmp', 'cache', 'assets', 'sprockets')
FileUtils.rm_rf(cache_path)

listener = Listen.to(Rails.root.join('app', 'assets', 'components')) do |_modified, _added, _removed|
# clearing cache
FileUtils.rm_rf(cache_path)
end
listener.start
end

0 comments on commit 0882ee7

Please sign in to comment.