rails-lineman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98e319f1d43ad61aee528dee66183d0d25263e34
4
+ data.tar.gz: 52f92a10c47f5f1014a7b4d45cca8f358660cd8d
5
+ SHA512:
6
+ metadata.gz: 7cc1e5d6a863e4b5c3414ad5c643a661a816c15cf0288f7aa21ee95717cee541d5b1a7faef47ad70310fec9875dfd493dff03bdd7f90d3b63201cf2ed506b723
7
+ data.tar.gz: d31bbed28501458cc1e85c3206386f4751c29ddbd9d75d6195dd136cf77853597dab916f02aafc701f3c2e5037a95659098b9fbac6652ea4c4f950e043ce409f
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-lineman.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Test Double
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # rails-lineman
2
+
3
+ Add this gem to your Gemfile if you want to deploy a lineman application with your
4
+ assets.
5
+
6
+ Wraps the `assets:precompile` rake task by building a specified lineman project.
7
+
8
+ All you need to set is a config property `Rails.application.config.rails_lineman.lineman_project_location` or environment variable $LINEMAN_PROJECT_LOCATION.
9
+
10
+ From your templates you'll be able to require lineman-built JS & CSS like so:
11
+
12
+ ``` erb
13
+ <%= stylesheet_link_tag "lineman/app" %>
14
+ <%= javascript_include_tag "lineman/app" %>
15
+ ```
16
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "rails_lineman/version"
2
+ require "rails_lineman/railtie" if defined?(Rails)
3
+
4
+ module RailsLineman
5
+ end
@@ -0,0 +1,8 @@
1
+ module Rake
2
+ TaskManager.class_eval do
3
+ def __lineman_rails__alias_task(fq_name)
4
+ new_name = "#{fq_name}:original"
5
+ @tasks[new_name] = @tasks.delete(fq_name)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,109 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+
4
+ module RailsLineman
5
+ class LinemanDoer
6
+ def initialize(config)
7
+ @lineman_project_location = config.lineman_project_location
8
+ @javascripts_destination = Rails.root.join(config.javascripts_destination)
9
+ @stylesheets_destination = Rails.root.join(config.stylesheets_destination)
10
+ @remove_lineman_assets_after_asset_pipeline_precompilation = config.remove_lineman_assets_after_asset_pipeline_precompilation
11
+ end
12
+
13
+ def build
14
+ absolutify_lineman_path
15
+ chdir @lineman_project_location do
16
+ run_npm_install
17
+ run_lineman_build
18
+ end
19
+ copy_javascripts
20
+ add_javascripts_to_precompile_list
21
+ copy_stylesheets
22
+ add_stylesheets_to_precompile_list
23
+ end
24
+
25
+ def destroy
26
+ return unless @remove_lineman_assets_after_asset_pipeline_precompilation
27
+ delete_javascripts
28
+ delete_stylesheets
29
+ end
30
+
31
+ private
32
+
33
+ def absolutify_lineman_path
34
+ @lineman_project_location = Pathname.new(@lineman_project_location).realpath.to_s
35
+ rescue => error
36
+ puts <<-ERROR
37
+
38
+ rails-lineman was not able to find your Lineman project at the path: `#{@lineman_project_location}`
39
+
40
+ To configure the plugin to find your Lineman project, set one of these to its path:
41
+ * An environment variable $LINEMAN_PROJECT_LOCATION
42
+ * The config property `Rails.application.config.rails_lineman.lineman_project_location`
43
+
44
+ ERROR
45
+ raise error
46
+ end
47
+
48
+ def chdir(path)
49
+ og_dir = Dir.pwd
50
+ Dir.chdir(path)
51
+ yield
52
+ Dir.chdir(og_dir)
53
+ end
54
+
55
+ def run_npm_install
56
+ return if system "npm install"
57
+ raise <<-ERROR
58
+
59
+ rails-lineman failed while running `npm install` from the `#{@lineman_project_location}` directory.
60
+
61
+ Make sure that you have Node.js installed on your system and that `npm` is on your PATH.
62
+
63
+ You can download Node.js here: http://nodejs.org
64
+
65
+ ERROR
66
+ end
67
+
68
+ def run_lineman_build
69
+ return if system "lineman build"
70
+ return if system "./node_modules/.bin/lineman build"
71
+
72
+ raise <<-ERROR
73
+
74
+ rails-lineman failed when trying to run `lineman build`.
75
+
76
+ Attempted to execute `lineman` as if on your PATH, then directly from
77
+ the npm binstub at `./node_modules/.bin/lineman`.
78
+
79
+ Try again after installing lineman globally with `npm install -g lineman`
80
+
81
+ ERROR
82
+ end
83
+
84
+ def copy_javascripts
85
+ FileUtils.cp_r(File.join(@lineman_project_location, "dist", "js"), @javascripts_destination)
86
+ end
87
+
88
+ def add_javascripts_to_precompile_list
89
+ Rails.application.config.assets.precompile += Dir.glob("#{@javascripts_destination}/**/*.js")
90
+ end
91
+
92
+ def copy_stylesheets
93
+ FileUtils.cp_r(File.join(@lineman_project_location, "dist", "css"), @stylesheets_destination)
94
+ end
95
+
96
+ def add_stylesheets_to_precompile_list
97
+ Rails.application.config.assets.precompile += Dir.glob("#{@stylesheets_destination}/**/*.css")
98
+ end
99
+
100
+ def delete_javascripts
101
+ FileUtils.rm_rf(@javascripts_destination)
102
+ end
103
+
104
+ def delete_stylesheets
105
+ FileUtils.rm_rf(@stylesheets_destination)
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,14 @@
1
+ module RailsLineman
2
+ class Railtie < Rails::Railtie
3
+ config.rails_lineman = ActiveSupport::OrderedOptions.new
4
+
5
+ config.rails_lineman.lineman_project_location = ENV['LINEMAN_PROJECT_LOCATION']
6
+ config.rails_lineman.javascripts_destination = File.join("app", "assets","javascripts", "lineman")
7
+ config.rails_lineman.stylesheets_destination = File.join("app", "assets","stylesheets", "lineman")
8
+ config.rails_lineman.remove_lineman_assets_after_asset_pipeline_precompilation = true
9
+
10
+ rake_tasks do
11
+ load(File.join(File.dirname(__FILE__), '..', 'tasks', 'assets_precompile.rake'))
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ #shamelessly cribbed from http://metaskills.net/2010/05/26/the-alias_method_chain-of-rake-override-rake-task/
2
+
3
+ require 'rails_lineman/ext/rake/task_manager'
4
+
5
+ module RailsLineman
6
+ module TaskHelpers
7
+ def self.alias_task(fq_name)
8
+ Rake.application.__lineman_rails__alias_task(fq_name)
9
+ end
10
+
11
+ def self.override_task(*args, &block)
12
+ name, params, deps = Rake.application.resolve_args(args.dup)
13
+ scope = Rake.application.instance_variable_get(:@scope).dup
14
+ fq_name = if scope.respond_to?(:push)
15
+ scope.push(name).join(':')
16
+ else
17
+ scope.to_a.reverse.push(name).join(':')
18
+ end
19
+ self.alias_task(fq_name)
20
+ Rake::Task.define_task(*args, &block)
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,3 @@
1
+ module RailsLineman
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_lineman/task_helpers'
2
+
3
+ require 'rails_lineman/lineman_doer'
4
+
5
+ namespace :assets do
6
+ desc 'Compile all the assets named in config.assets.precompile (Wrapped by rails-lineman)'
7
+ RailsLineman::TaskHelpers.override_task :precompile => :environment do
8
+ lineman_doer = RailsLineman::LinemanDoer.new(Rails.application.config.rails_lineman)
9
+ lineman_doer.build
10
+ Rake::Task["assets:precompile:original"].execute
11
+ lineman_doer.destroy
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_lineman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-lineman"
8
+ spec.version = RailsLineman::VERSION
9
+ spec.authors = ["Justin Searls"]
10
+ spec.email = ["searls@gmail.com"]
11
+ spec.description = %q{Helps Rails apps integrate a Lineman into their build by wrapping rake assets:precompile}
12
+ spec.summary = %q{Helps Rails apps integrate a Lineman into their build by wrapping rake assets:precompile.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rake"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-lineman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Searls
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ description: Helps Rails apps integrate a Lineman into their build by wrapping rake
42
+ assets:precompile
43
+ email:
44
+ - searls@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/rails-lineman.rb
55
+ - lib/rails_lineman/ext/rake/task_manager.rb
56
+ - lib/rails_lineman/lineman_doer.rb
57
+ - lib/rails_lineman/railtie.rb
58
+ - lib/rails_lineman/task_helpers.rb
59
+ - lib/rails_lineman/version.rb
60
+ - lib/tasks/assets_precompile.rake
61
+ - rails-lineman.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Helps Rails apps integrate a Lineman into their build by wrapping rake assets:precompile.
86
+ test_files: []