redmine_plugin_asset_pipeline 0.0.14 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/init.rb +1 -4
- data/lib/redmine_plugin_asset_pipeline.rb +5 -58
- data/lib/redmine_plugin_asset_pipeline/configuration.rb +11 -0
- data/lib/redmine_plugin_asset_pipeline/infectors.rb +5 -0
- data/lib/redmine_plugin_asset_pipeline/infectors/application_helper.rb +99 -0
- data/lib/redmine_plugin_asset_pipeline/infectors/redmine.rb +5 -0
- data/lib/redmine_plugin_asset_pipeline/infectors/redmine/plugin.rb +71 -0
- data/lib/redmine_plugin_asset_pipeline/infectors/redmine/themes.rb +4 -0
- data/lib/redmine_plugin_asset_pipeline/infectors/redmine/themes/theme.rb +7 -0
- data/lib/redmine_plugin_asset_pipeline/plugin.rb +48 -0
- data/lib/redmine_plugin_asset_pipeline/sprockets_processor.rb +22 -24
- data/lib/redmine_plugin_asset_pipeline/version.rb +1 -1
- data/redmine_plugin_asset_pipeline.gemspec +10 -8
- metadata +38 -4
- data/lib/redmine_plugin_asset_pipeline/application_helper_patch.rb +0 -173
- data/lib/redmine_plugin_asset_pipeline/plugin_patch.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf025bc1015abb4de87d4c96aa488c162fade8d
|
4
|
+
data.tar.gz: 65ccd07b3a8210590bf8c0ba5dc8518cdea2ac76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d3d0b48bbf43b86ed380454003f610da575dd8d0edd3827d4b768e7d613f4c16a1dd593e09a27f0ae779c88941a8e125cb70d5ae92698e702312662f193e861
|
7
|
+
data.tar.gz: 57862b10a64a8bb5350899a3c7688c89fd21ec50f29ac4dd562a78e9be4161c25415a1f10172cf9d1396ecd421b823bc976b942d6606fc2ce584915fd7427dc9
|
data/init.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require 'redmine'
|
2
|
-
require 'redmine_plugin_asset_pipeline/version'
|
3
|
-
|
4
1
|
Redmine::Plugin.register :redmine_plugin_asset_pipeline do
|
5
2
|
name 'Redmine Plugin Asset Pipeline plugin'
|
6
3
|
description 'This plugin adds asset pipeline support for redmine plugins'
|
7
4
|
url 'https://github.com/Tab10id/redmine_plugin_asset_pipeline'
|
8
5
|
version RedminePluginAssetPipeline::VERSION
|
9
|
-
requires_redmine :
|
6
|
+
requires_redmine version_or_higher: '3.0.0'
|
10
7
|
end
|
@@ -1,17 +1,11 @@
|
|
1
1
|
require 'redmine_plugin_asset_pipeline/version'
|
2
|
+
require 'redmine_plugin_asset_pipeline/plugin'
|
2
3
|
|
3
4
|
module RedminePluginAssetPipeline
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@use_ln = false
|
9
|
-
end
|
10
|
-
|
11
|
-
def [](value)
|
12
|
-
self.public_send(value)
|
13
|
-
end
|
14
|
-
end
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
autoload :Configuration
|
7
|
+
autoload :Infectors
|
8
|
+
autoload :Rails
|
15
9
|
|
16
10
|
def self.configure
|
17
11
|
self.config ||= Configuration.new
|
@@ -22,53 +16,6 @@ module RedminePluginAssetPipeline
|
|
22
16
|
@config
|
23
17
|
end
|
24
18
|
|
25
|
-
# Run the classic redmine plugin initializer after rails boot
|
26
|
-
class Plugin < ::Rails::Engine
|
27
|
-
config.after_initialize do
|
28
|
-
require File.expand_path('../../init', __FILE__)
|
29
|
-
end
|
30
|
-
|
31
|
-
#asset pipeline configuration
|
32
|
-
#enable asset pipeline before sprockets boots
|
33
|
-
initializer 'redmine.asset_pipeline', before: 'sprockets.environment' do
|
34
|
-
RedmineApp::Application.configure do
|
35
|
-
config.assets.paths << "#{config.root}/private/plugin_assets"
|
36
|
-
config.assets.precompile += %w(*/stylesheets/*.css */javascripts/*.js)
|
37
|
-
# Custom settings. Edit configs of your application
|
38
|
-
# See: http://guides.rubyonrails.org/asset_pipeline.html
|
39
|
-
#
|
40
|
-
# Redmine save all assets in root of public =(
|
41
|
-
# If you need to change that value
|
42
|
-
# manually move assets in public directory and edit it
|
43
|
-
# config.assets.prefix = ''
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#add all plugin directories in case some js/css/images are included directly or via relative css
|
48
|
-
#it also avoids Sprocket's FileOutsidePaths errors
|
49
|
-
# config.assets.paths += Dir.glob("#{config.root}/plugins/*/assets")
|
50
|
-
#add our directory
|
51
|
-
# config.assets.paths += Dir.glob("#{File.dirname(__FILE__)}/assets")
|
52
|
-
#compression
|
53
|
-
# config.assets.compress = true
|
54
|
-
# config.assets.css_compressor = :yui
|
55
|
-
# config.assets.js_compressor = :yui
|
56
|
-
|
57
|
-
# Register our processor (subclass of the standard one which adds a directive for redmine plugins)
|
58
|
-
initializer 'redmine.sprockets_processor', after: 'sprockets.environment' do
|
59
|
-
require 'redmine_plugin_asset_pipeline/sprockets_processor'
|
60
|
-
env = RedmineApp::Application.assets
|
61
|
-
env.unregister_preprocessor('text/css', Sprockets::DirectiveProcessor)
|
62
|
-
env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
|
63
|
-
env.register_preprocessor('text/css', RedminePluginAssetPipeline::SprocketsProcessor)
|
64
|
-
env.register_preprocessor('application/javascript', RedminePluginAssetPipeline::SprocketsProcessor)
|
65
|
-
end
|
66
|
-
|
67
|
-
config.to_prepare do
|
68
|
-
require_dependency 'redmine_plugin_asset_pipeline/application_helper_patch'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
19
|
private
|
73
20
|
|
74
21
|
def self.config=(value)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module RedminePluginAssetPipeline::Infectors::ApplicationHelper
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
def stylesheet_link_tag(*sources)
|
6
|
+
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
7
|
+
plugin = options.delete(:plugin)
|
8
|
+
sources = sources.map do |source|
|
9
|
+
if plugin
|
10
|
+
"#{plugin}/stylesheets/#{source}"
|
11
|
+
elsif current_theme && current_theme.stylesheets.include?(source)
|
12
|
+
current_theme.stylesheet_path(source)
|
13
|
+
else
|
14
|
+
# @note: assets from gems
|
15
|
+
[source, "stylesheets/#{source}"].find do |s|
|
16
|
+
asset_digest_path("#{s}#{compute_asset_extname(s, type: :stylesheet)}").present?
|
17
|
+
end || source
|
18
|
+
end
|
19
|
+
end
|
20
|
+
sprockets_helper_context.stylesheet_link_tag(*sources, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def javascript_include_tag(*sources)
|
24
|
+
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
25
|
+
plugin = options.delete(:plugin)
|
26
|
+
sources = sources.map do |source|
|
27
|
+
if plugin
|
28
|
+
"#{plugin}/javascripts/#{source}"
|
29
|
+
else
|
30
|
+
# @note: assets from gems
|
31
|
+
[source, "javascripts/#{source}"].find do |s|
|
32
|
+
asset_digest_path("#{s}#{compute_asset_extname(s, type: :javascript)}").present?
|
33
|
+
end || source
|
34
|
+
end
|
35
|
+
end
|
36
|
+
sprockets_helper_context.javascript_include_tag(*sources, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def image_tag(source, options={})
|
40
|
+
plugin = options.delete(:plugin)
|
41
|
+
if plugin
|
42
|
+
source = "#{plugin}/images/#{source}"
|
43
|
+
elsif current_theme && current_theme.images.include?(source)
|
44
|
+
source = current_theme.image_path(source)
|
45
|
+
else
|
46
|
+
source = [source, "images/#{source}"].find{ |s| asset_digest_path(s).present? } || source
|
47
|
+
end
|
48
|
+
sprockets_helper_context.image_tag(source, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Only one fix - remove leading slash in path_to_image
|
52
|
+
def include_calendar_headers_tags
|
53
|
+
unless @calendar_headers_tags_included
|
54
|
+
tags = ''.html_safe
|
55
|
+
@calendar_headers_tags_included = true
|
56
|
+
content_for :header_tags do
|
57
|
+
start_of_week = Setting.start_of_week
|
58
|
+
start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
|
59
|
+
# Redmine uses 1..7 (monday..sunday) in settings and locales
|
60
|
+
# JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
|
61
|
+
start_of_week = start_of_week.to_i % 7
|
62
|
+
tags << javascript_tag(
|
63
|
+
"var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
|
64
|
+
"showOn: 'button', buttonImageOnly: true, buttonImage: '" +
|
65
|
+
path_to_image('images/calendar.png') +
|
66
|
+
"', showButtonPanel: true, showWeek: true, showOtherMonths: true, " +
|
67
|
+
"selectOtherMonths: true, changeMonth: true, changeYear: true, " +
|
68
|
+
"beforeShow: beforeShowDatePicker};")
|
69
|
+
jquery_locale = l('jquery.locale', :default => current_language.to_s)
|
70
|
+
unless jquery_locale == 'en'
|
71
|
+
tags << javascript_include_tag("i18n/datepicker-#{jquery_locale}.js")
|
72
|
+
end
|
73
|
+
tags
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def sprockets_helper_context
|
79
|
+
@context ||= Class.new do
|
80
|
+
include Sprockets::Rails::Helper
|
81
|
+
# Copy relevant config to AV context
|
82
|
+
app = Rails.application
|
83
|
+
config = app.config
|
84
|
+
self.debug_assets = config.assets.debug
|
85
|
+
self.digest_assets = config.assets.digest
|
86
|
+
self.assets_prefix = config.assets.prefix
|
87
|
+
|
88
|
+
# Copy over to Sprockets as well
|
89
|
+
context = app.assets.context_class
|
90
|
+
context.assets_prefix = config.assets.prefix
|
91
|
+
context.digest_assets = config.assets.digest
|
92
|
+
context.config = config.action_controller
|
93
|
+
|
94
|
+
self.assets_environment = app.assets if config.assets.compile
|
95
|
+
self.assets_manifest = app.assets_manifest
|
96
|
+
end.new
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Patch for copy plugin assets sources to private directory
|
2
|
+
module RedminePluginAssetPipeline::Infectors::Redmine::Plugin
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
alias_method :mirror_assets_to_public, :mirror_assets
|
7
|
+
alias_method :mirror_assets, :mirror_assets_to_private
|
8
|
+
|
9
|
+
class << self
|
10
|
+
cattr_accessor :private_directory_base
|
11
|
+
self.private_directory_base = File.join(Rails.root, 'private', 'plugin_assets')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def private_directory
|
16
|
+
File.join(self.class.private_directory_base, id.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mirror_assets_to_private
|
20
|
+
source = assets_directory
|
21
|
+
destination = private_directory
|
22
|
+
|
23
|
+
unless File.exist?(self.class.private_directory_base)
|
24
|
+
FileUtils.mkdir_p(self.class.private_directory_base)
|
25
|
+
end
|
26
|
+
|
27
|
+
if File.exist?(destination)
|
28
|
+
FileUtils.rm_rf(destination)
|
29
|
+
end
|
30
|
+
return unless File.directory?(source)
|
31
|
+
|
32
|
+
if RedminePluginAssetPipeline.config.use_ln
|
33
|
+
if File.exist?(source)
|
34
|
+
FileUtils.ln_s(source, destination)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
source_files = Dir[source + '/**/*']
|
38
|
+
source_dirs = source_files.select { |d| File.directory?(d) }
|
39
|
+
source_files -= source_dirs
|
40
|
+
unless source_files.empty?
|
41
|
+
base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
|
42
|
+
begin
|
43
|
+
FileUtils.mkdir_p(base_target_dir)
|
44
|
+
rescue Exception => e
|
45
|
+
raise "Could not create directory #{base_target_dir}: " + e.message
|
46
|
+
end
|
47
|
+
end
|
48
|
+
source_dirs.each do |dir|
|
49
|
+
# strip down these paths so we have simple, relative paths we can
|
50
|
+
# add to the destination
|
51
|
+
target_dir = File.join(destination, dir.gsub(source, ''))
|
52
|
+
begin
|
53
|
+
FileUtils.mkdir_p(target_dir)
|
54
|
+
rescue Exception => e
|
55
|
+
raise "Could not create directory #{target_dir}: " + e.message
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
source_files.each do |file|
|
60
|
+
begin
|
61
|
+
target = File.join(destination, file.gsub(source, ''))
|
62
|
+
unless File.exist?(target) && FileUtils.identical?(file, target)
|
63
|
+
FileUtils.cp(file, target)
|
64
|
+
end
|
65
|
+
rescue Exception => e
|
66
|
+
raise "Could not copy #{file} to #{target}: " + e.message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class RedminePluginAssetPipeline::Plugin < ::Rails::Engine
|
2
|
+
config.after_initialize do
|
3
|
+
require File.expand_path('../../../init', __FILE__)
|
4
|
+
end
|
5
|
+
|
6
|
+
#asset pipeline configuration
|
7
|
+
#enable asset pipeline before sprockets boots
|
8
|
+
initializer 'redmine.asset_pipeline', before: 'sprockets.environment' do
|
9
|
+
RedmineApp::Application.configure do
|
10
|
+
config.assets.paths << "#{config.root}/private/plugin_assets"
|
11
|
+
config.assets.precompile += %w(*/stylesheets/*.css */javascripts/*.js */images/* */fonts/*)
|
12
|
+
# Custom settings. Edit configs of your application
|
13
|
+
# See: http://guides.rubyonrails.org/asset_pipeline.html
|
14
|
+
#
|
15
|
+
# Redmine save all assets in root of public =(
|
16
|
+
# If you need to change that value
|
17
|
+
# manually move assets in public directory and edit it
|
18
|
+
# config.assets.prefix = ''
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#add all plugin directories in case some js/css/images are included directly or via relative css
|
23
|
+
#it also avoids Sprocket's FileOutsidePaths errors
|
24
|
+
# config.assets.paths += Dir.glob("#{config.root}/plugins/*/assets")
|
25
|
+
#add our directory
|
26
|
+
# config.assets.paths += Dir.glob("#{File.dirname(__FILE__)}/assets")
|
27
|
+
#compression
|
28
|
+
# config.assets.compress = true
|
29
|
+
# config.assets.css_compressor = :yui
|
30
|
+
# config.assets.js_compressor = :yui
|
31
|
+
|
32
|
+
# Register our processor (subclass of the standard one which adds a directive for redmine plugins)
|
33
|
+
initializer 'redmine.sprockets_processor', after: 'sprockets.environment' do
|
34
|
+
require 'redmine_plugin_asset_pipeline/sprockets_processor'
|
35
|
+
env = RedmineApp::Application.assets
|
36
|
+
env.unregister_preprocessor('text/css', Sprockets::DirectiveProcessor)
|
37
|
+
env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
|
38
|
+
env.register_preprocessor('text/css', RedminePluginAssetPipeline::SprocketsProcessor)
|
39
|
+
env.register_preprocessor('application/javascript', RedminePluginAssetPipeline::SprocketsProcessor)
|
40
|
+
end
|
41
|
+
|
42
|
+
config.to_prepare do
|
43
|
+
require_dependency 'application_helper'
|
44
|
+
unless ApplicationHelper.included_modules.include? RedminePluginAssetPipeline::Infectors::ApplicationHelper
|
45
|
+
ApplicationHelper.send(:include, RedminePluginAssetPipeline::Infectors::ApplicationHelper)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,28 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# end
|
1
|
+
class RedminePluginAssetPipeline::SprocketsProcessor < Sprockets::DirectiveProcessor
|
2
|
+
# This processor subclasses the standard Sprockets::DirectiveProcessor
|
3
|
+
# as advised in Sprockets, to add a new directive called
|
4
|
+
# "require_redmine_plugins". This directive is relative to the
|
5
|
+
# #{Rails.root}/plugins/ directory and accepts wildcards.
|
6
|
+
#
|
7
|
+
# For convenience, it also replaces "ALL" by a star ("*") before
|
8
|
+
# evaluating the globing. Otherwise, "*/" is interpreted as the end of
|
9
|
+
# the comment in CSS files, which is obviously problematic.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# For the record, here's the example custom require provided in sprockets:
|
13
|
+
#
|
14
|
+
# def process_require_glob_directive
|
15
|
+
# Dir["#{pathname.dirname}/#{glob}"].sort.each do |filename|
|
16
|
+
# require(filename)
|
17
|
+
# end
|
18
|
+
# end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
20
|
+
def process_require_redmine_plugins_directive(type, prefix='')
|
21
|
+
mask = Rails.root.join(Redmine::Plugin.private_directory_base, "*/#{type}/#{prefix}_common_part*").expand_path
|
22
|
+
Dir.glob(mask).sort.each do |entry|
|
23
|
+
context.require_asset(pathname.dirname.join(entry).expand_path)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -4,20 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'redmine_plugin_asset_pipeline/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'redmine_plugin_asset_pipeline'
|
8
8
|
spec.version = RedminePluginAssetPipeline::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Tab10id']
|
10
|
+
spec.email = ['tabloidmeister@gmail.com']
|
11
11
|
spec.description = %q{Asset pipeline for Redmine}
|
12
12
|
spec.summary = %q{Asset pipeline for Redmine}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/Tab10id/redmine_plugin_asset_pipeline'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
21
|
+
spec.add_dependency 'actionview', '>= 4.0'
|
22
|
+
spec.add_dependency 'sprockets', '>= 2.0'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
23
25
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine_plugin_asset_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tab10id
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sprockets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,8 +82,14 @@ files:
|
|
54
82
|
- lib/generators/redmine_pipeline/private_assets_initializer/private_assets_initializer_generator.rb
|
55
83
|
- lib/generators/redmine_pipeline/private_assets_initializer/templates/35-patch_assets_mirror.rb
|
56
84
|
- lib/redmine_plugin_asset_pipeline.rb
|
57
|
-
- lib/redmine_plugin_asset_pipeline/
|
58
|
-
- lib/redmine_plugin_asset_pipeline/
|
85
|
+
- lib/redmine_plugin_asset_pipeline/configuration.rb
|
86
|
+
- lib/redmine_plugin_asset_pipeline/infectors.rb
|
87
|
+
- lib/redmine_plugin_asset_pipeline/infectors/application_helper.rb
|
88
|
+
- lib/redmine_plugin_asset_pipeline/infectors/redmine.rb
|
89
|
+
- lib/redmine_plugin_asset_pipeline/infectors/redmine/plugin.rb
|
90
|
+
- lib/redmine_plugin_asset_pipeline/infectors/redmine/themes.rb
|
91
|
+
- lib/redmine_plugin_asset_pipeline/infectors/redmine/themes/theme.rb
|
92
|
+
- lib/redmine_plugin_asset_pipeline/plugin.rb
|
59
93
|
- lib/redmine_plugin_asset_pipeline/sprockets_processor.rb
|
60
94
|
- lib/redmine_plugin_asset_pipeline/version.rb
|
61
95
|
- redmine_plugin_asset_pipeline.gemspec
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require_dependency 'application_helper'
|
2
|
-
|
3
|
-
module ApplicationHelper
|
4
|
-
def stylesheet_link_tag(*sources)
|
5
|
-
options = sources.extract_options!
|
6
|
-
plugin = options.delete(:plugin)
|
7
|
-
debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
|
8
|
-
body = options.key?(:body) ? options.delete(:body) : false
|
9
|
-
digest = options.key?(:digest) ? options.delete(:digest) : digest_assets?
|
10
|
-
sources.map! do |source|
|
11
|
-
if plugin
|
12
|
-
"#{plugin}/stylesheets/#{source}"
|
13
|
-
elsif current_theme && current_theme.stylesheets.include?(source)
|
14
|
-
current_theme.stylesheet_path(source)
|
15
|
-
else
|
16
|
-
# NOTE: bugfix aka crutch for asset from gem
|
17
|
-
["stylesheets/#{source}", source].
|
18
|
-
find{|s| asset_for(s, 'css').present?} || "stylesheets/#{source}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
sources.collect do |source|
|
22
|
-
asset = asset_for(source, 'css')
|
23
|
-
if debug && asset
|
24
|
-
asset.to_a.map do |dep|
|
25
|
-
single_asset_path = asset_path(dep, ext: 'css',
|
26
|
-
body: true,
|
27
|
-
protocol: :request,
|
28
|
-
digest: digest)
|
29
|
-
# TODO: here we must try to make more pretty solution
|
30
|
-
next if single_asset_path.blank?
|
31
|
-
super(dep.pathname.to_s, { href: single_asset_path }.merge!(options))
|
32
|
-
end.compact
|
33
|
-
else
|
34
|
-
single_asset_path = asset_path(source, ext: 'css',
|
35
|
-
body: body,
|
36
|
-
protocol: :request,
|
37
|
-
digest: digest)
|
38
|
-
# TODO: here we must try to make more pretty solution
|
39
|
-
next if single_asset_path.blank?
|
40
|
-
super(source.to_s, { href: single_asset_path }.merge!(options))
|
41
|
-
end
|
42
|
-
end.compact.uniq.join("\n").html_safe
|
43
|
-
end
|
44
|
-
|
45
|
-
def javascript_include_tag(*sources)
|
46
|
-
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
47
|
-
plugin = options.delete(:plugin)
|
48
|
-
debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
|
49
|
-
body = options.key?(:body) ? options.delete(:body) : false
|
50
|
-
digest = options.key?(:digest) ? options.delete(:digest) : digest_assets?
|
51
|
-
sources.map! do |source|
|
52
|
-
if plugin
|
53
|
-
"#{plugin}/javascripts/#{source}"
|
54
|
-
else
|
55
|
-
# NOTE: bugfix aka crutch for asset from gem
|
56
|
-
["javascripts/#{source}", source].
|
57
|
-
find{|s| asset_for(s, 'js').present?} || "javascripts/#{source}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
sources.collect do |source|
|
61
|
-
asset = asset_for(source, 'js')
|
62
|
-
if debug && asset
|
63
|
-
asset.to_a.map do |dep|
|
64
|
-
single_asset_path = asset_path(dep, ext: 'js',
|
65
|
-
body: true,
|
66
|
-
digest: digest)
|
67
|
-
# TODO: here we must try to make more pretty solution
|
68
|
-
next if single_asset_path.blank?
|
69
|
-
super(dep.pathname.to_s, { src: single_asset_path }.merge!(options))
|
70
|
-
end.compact
|
71
|
-
else
|
72
|
-
single_asset_path = asset_path(source, ext: 'js',
|
73
|
-
body: body,
|
74
|
-
digest: digest)
|
75
|
-
# TODO: here we must try to make more pretty solution
|
76
|
-
next if single_asset_path.blank?
|
77
|
-
super(source.to_s, { src: single_asset_path }.merge!(options))
|
78
|
-
end
|
79
|
-
end.compact.uniq.join("\n").html_safe
|
80
|
-
end
|
81
|
-
|
82
|
-
def image_tag(source, options={})
|
83
|
-
if plugin = options.delete(:plugin)
|
84
|
-
source = "#{plugin}/images/#{source}"
|
85
|
-
elsif current_theme && current_theme.images.include?(source)
|
86
|
-
source = current_theme.image_path(source)
|
87
|
-
elsif source[0] != '/'
|
88
|
-
source = "images/#{source}"
|
89
|
-
end
|
90
|
-
super source, options
|
91
|
-
end
|
92
|
-
|
93
|
-
def include_calendar_headers_tags
|
94
|
-
unless @calendar_headers_tags_included
|
95
|
-
@calendar_headers_tags_included = true
|
96
|
-
content_for :header_tags do
|
97
|
-
start_of_week = Setting.start_of_week
|
98
|
-
start_of_week = l(:general_first_day_of_week, default: '1') if start_of_week.blank?
|
99
|
-
# Redmine uses 1..7 (monday..sunday) in settings and locales
|
100
|
-
# JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
|
101
|
-
start_of_week = start_of_week.to_i % 7
|
102
|
-
|
103
|
-
tags = javascript_tag(
|
104
|
-
"var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
|
105
|
-
"showOn: 'button', buttonImageOnly: true, buttonImage: '" +
|
106
|
-
path_to_image('images/calendar.png') +
|
107
|
-
"', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true};")
|
108
|
-
jquery_locale = l('jquery.locale', default: current_language.to_s)
|
109
|
-
unless jquery_locale == 'en'
|
110
|
-
tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js")
|
111
|
-
end
|
112
|
-
tags
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
# copy-paste from Sprocket
|
120
|
-
def debug_assets?
|
121
|
-
compile_assets? && (Rails.application.config.assets.debug || params[:debug_assets])
|
122
|
-
rescue NameError
|
123
|
-
false
|
124
|
-
end
|
125
|
-
|
126
|
-
def compile_assets?
|
127
|
-
Rails.application.config.assets.compile
|
128
|
-
end
|
129
|
-
|
130
|
-
def digest_assets?
|
131
|
-
Rails.application.config.assets.digest
|
132
|
-
end
|
133
|
-
|
134
|
-
def asset_path(source, options = {})
|
135
|
-
source = source.logical_path if source.respond_to?(:logical_path)
|
136
|
-
path = asset_paths.compute_public_path(source, assets_prefix, options.merge(body: true))
|
137
|
-
options[:body] ? "#{path}?body=1" : path
|
138
|
-
end
|
139
|
-
|
140
|
-
def assets_prefix
|
141
|
-
Rails.application.config.assets.prefix.gsub(/^\//, '')
|
142
|
-
end
|
143
|
-
|
144
|
-
def asset_for(source, ext)
|
145
|
-
source = source.to_s
|
146
|
-
return nil if asset_paths.is_uri?(source)
|
147
|
-
source = rewrite_extension(source, ext)
|
148
|
-
Rails.application.assets[source]
|
149
|
-
rescue Sprockets::FileOutsidePaths
|
150
|
-
nil
|
151
|
-
end
|
152
|
-
|
153
|
-
def rewrite_extension(source, ext)
|
154
|
-
source_ext = File.extname(source)[1..-1]
|
155
|
-
|
156
|
-
if !ext || ext == source_ext
|
157
|
-
source
|
158
|
-
elsif source_ext.blank?
|
159
|
-
"#{source}.#{ext}"
|
160
|
-
elsif File.exists?(source) || exact_match_present?(source)
|
161
|
-
source
|
162
|
-
else
|
163
|
-
"#{source}.#{ext}"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def exact_match_present?(source)
|
168
|
-
pathname = Rails.application.assets.resolve(source)
|
169
|
-
pathname.to_s =~ /#{Regexp.escape(source)}\Z/
|
170
|
-
rescue Sprockets::FileNotFound
|
171
|
-
false
|
172
|
-
end
|
173
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# Patch for copy plugin assets sources to private directory
|
2
|
-
module RedminePluginAssetPipeline
|
3
|
-
module PluginPatch
|
4
|
-
def self.included(base)
|
5
|
-
|
6
|
-
base.extend(ClassMethods)
|
7
|
-
base.send(:include, InstanceMethods)
|
8
|
-
|
9
|
-
base.class_eval do
|
10
|
-
class << self
|
11
|
-
cattr_accessor :private_directory
|
12
|
-
self.private_directory = File.join(Rails.root, 'private', 'plugin_assets')
|
13
|
-
end
|
14
|
-
|
15
|
-
alias_method :mirror_assets_to_public, :mirror_assets
|
16
|
-
alias_method :mirror_assets, :mirror_assets_to_private
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
end
|
22
|
-
|
23
|
-
module InstanceMethods
|
24
|
-
def private_directory
|
25
|
-
File.join(self.class.private_directory, id.to_s)
|
26
|
-
end
|
27
|
-
|
28
|
-
def mirror_assets_to_private
|
29
|
-
source = assets_directory
|
30
|
-
destination = private_directory
|
31
|
-
|
32
|
-
unless File.exist?(self.class.private_directory)
|
33
|
-
FileUtils.mkdir_p(self.class.private_directory)
|
34
|
-
end
|
35
|
-
|
36
|
-
if File.exist?(destination)
|
37
|
-
FileUtils.rm_rf(destination)
|
38
|
-
end
|
39
|
-
return unless File.directory?(source)
|
40
|
-
|
41
|
-
if RedminePluginAssetPipeline.config.use_ln
|
42
|
-
if File.exist?(source)
|
43
|
-
FileUtils.ln_s(source, destination)
|
44
|
-
end
|
45
|
-
else
|
46
|
-
source_files = Dir[source + "/**/*"]
|
47
|
-
source_dirs = source_files.select { |d| File.directory?(d) }
|
48
|
-
source_files -= source_dirs
|
49
|
-
unless source_files.empty?
|
50
|
-
base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
|
51
|
-
begin
|
52
|
-
FileUtils.mkdir_p(base_target_dir)
|
53
|
-
rescue Exception => e
|
54
|
-
raise "Could not create directory #{base_target_dir}: " + e.message
|
55
|
-
end
|
56
|
-
end
|
57
|
-
source_dirs.each do |dir|
|
58
|
-
# strip down these paths so we have simple, relative paths we can
|
59
|
-
# add to the destination
|
60
|
-
target_dir = File.join(destination, dir.gsub(source, ''))
|
61
|
-
begin
|
62
|
-
FileUtils.mkdir_p(target_dir)
|
63
|
-
rescue Exception => e
|
64
|
-
raise "Could not create directory #{target_dir}: " + e.message
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
source_files.each do |file|
|
69
|
-
begin
|
70
|
-
target = File.join(destination, file.gsub(source, ''))
|
71
|
-
unless File.exist?(target) && FileUtils.identical?(file, target)
|
72
|
-
FileUtils.cp(file, target)
|
73
|
-
end
|
74
|
-
rescue Exception => e
|
75
|
-
raise "Could not copy #{file} to #{target}: " + e.message
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|