taskjuggler-rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README.md +17 -0
- data/lib/taskjuggler-rails.rb +15 -0
- data/lib/taskjuggler_rails/engine.rb +27 -0
- data/lib/taskjuggler_rails/renderer.rb +91 -0
- data/lib/taskjuggler_rails/version.rb +3 -0
- metadata +75 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4e29c7064e3c43146fafc4c9c8e95cefa754facbaa18bd440ba46e8ebdeb3855
|
|
4
|
+
data.tar.gz: db07e87d55f50343147e1b1027f00c64b57ffd2bbf696a3f1a5ae055be47b7b2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b472a78cb64d3ffe48486b9bb78802739f7985f48a4a6098b1b2d40c94ea5f79a383a433403a1c29ecb5563131e2c310ab3b44cd57a3cca680cf81be76f697ec
|
|
7
|
+
data.tar.gz: 1fbc6e7249346a8d72e05c756b6b0f182b9e4d3d86c225d8288f0d6d4a93fa0da156c06b942820c17ee403875d6c5d09470c176156928d8693f280f6e4c6af0c
|
data/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Nathan Kidd
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# taskjuggler-rails
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
Add this line to your application's Gemfile:
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
gem "taskjuggler-rails"
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
or
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bundle add "taskjuggler-rails"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "action_controller"
|
|
2
|
+
require "active_support"
|
|
3
|
+
|
|
4
|
+
module TaskjugglerRails
|
|
5
|
+
mattr_accessor :config, default: ActiveSupport::OrderedOptions.new.merge(
|
|
6
|
+
tj3_path: Gem.bin_path("taskjuggler", "tj3"),
|
|
7
|
+
tj3_args: {}
|
|
8
|
+
)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require "taskjuggler_rails/version"
|
|
12
|
+
require "taskjuggler_rails/renderer"
|
|
13
|
+
require "taskjuggler_rails/engine"
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module TaskjugglerRails
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace TaskjugglerRails
|
|
4
|
+
|
|
5
|
+
initializer "taskjuggler_rails.template_handlers" do
|
|
6
|
+
ActionView::Template.register_template_handler :tjp, proc { |template|
|
|
7
|
+
<<~RUBY
|
|
8
|
+
# Create a proper view context with full assigns and helpers
|
|
9
|
+
view = ActionView::Base.with_view_paths(
|
|
10
|
+
ActionController::Base.view_paths,
|
|
11
|
+
assigns.merge(local_assigns),
|
|
12
|
+
controller
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
# This gives us: @effort, helpers, params, current_user, etc.
|
|
16
|
+
# No extend needed — with_view_paths already includes helpers
|
|
17
|
+
|
|
18
|
+
tjp_source = view.instance_eval do
|
|
19
|
+
ERB.new(#{template.source.inspect}, trim_mode: '-').result(binding)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
TaskjugglerRails::Renderer.render_html(tjp_source)
|
|
23
|
+
RUBY
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module TaskjugglerRails
|
|
2
|
+
module Renderer
|
|
3
|
+
module_function
|
|
4
|
+
|
|
5
|
+
def render_html(tjp_source)
|
|
6
|
+
Dir.mktmpdir("tjp") do |dir|
|
|
7
|
+
input_tjp = File.join(dir, "input.tjp")
|
|
8
|
+
output_dir = File.join(dir, "out")
|
|
9
|
+
FileUtils.mkdir_p(output_dir)
|
|
10
|
+
|
|
11
|
+
File.write(input_tjp, tjp_source)
|
|
12
|
+
|
|
13
|
+
exe = resolve_tj3_path
|
|
14
|
+
args = TaskjugglerRails.config.tj3_args.flat_map { |k, v| ["--#{k}", v.to_s] }
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# IMPORTANT:
|
|
18
|
+
# TaskJuggler syntax requires:
|
|
19
|
+
#
|
|
20
|
+
# --output-dir <directory>
|
|
21
|
+
#
|
|
22
|
+
cmd = [
|
|
23
|
+
exe,
|
|
24
|
+
input_tjp,
|
|
25
|
+
"--output-dir", output_dir,
|
|
26
|
+
*args
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
log = `#{cmd.join(" ")} 2>&1`
|
|
30
|
+
|
|
31
|
+
html_file = Dir[File.join(output_dir, "*.html")].first
|
|
32
|
+
raise "TaskJuggler produced no HTML.\n#{log}" unless html_file
|
|
33
|
+
|
|
34
|
+
html = File.read(html_file)
|
|
35
|
+
|
|
36
|
+
embed_assets(html, output_dir)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ----------------------------------------------------------
|
|
42
|
+
# Asset embedding (css/js/icons) same as before
|
|
43
|
+
# ----------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
def embed_assets(html, output_dir)
|
|
46
|
+
doc = Nokogiri::HTML(html)
|
|
47
|
+
|
|
48
|
+
Dir[File.join(output_dir, "css/*.css")].each do |css_file|
|
|
49
|
+
node = Nokogiri::XML::Node.new("style", doc)
|
|
50
|
+
node.content = File.read(css_file)
|
|
51
|
+
doc.at("head") << node
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
doc.css('link').each { |l| l.remove if l["href"].to_s.start_with?("css/") }
|
|
55
|
+
|
|
56
|
+
Dir[File.join(output_dir, "scripts/*.js")].each do |js_file|
|
|
57
|
+
node = Nokogiri::XML::Node.new("script", doc)
|
|
58
|
+
node.content = File.read(js_file)
|
|
59
|
+
doc.at("body") << node
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
doc.css("script").each { |s| s.remove if s["src"].to_s.start_with?("scripts/") }
|
|
63
|
+
|
|
64
|
+
doc.css("img").each do |img|
|
|
65
|
+
src = img["src"].to_s
|
|
66
|
+
next unless src.start_with?("icons/")
|
|
67
|
+
|
|
68
|
+
icon_path = File.join(output_dir, src)
|
|
69
|
+
next unless File.exist?(icon_path)
|
|
70
|
+
|
|
71
|
+
mime = "image/#{File.extname(icon_path).delete('.')}"
|
|
72
|
+
encoded = Base64.strict_encode64(File.binread(icon_path))
|
|
73
|
+
img["src"] = "data:#{mime};base64,#{encoded}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
doc.to_html
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def resolve_tj3_path
|
|
81
|
+
explicit = TaskjugglerRails.config.tj3_path
|
|
82
|
+
return explicit if explicit && File.exist?(explicit)
|
|
83
|
+
|
|
84
|
+
path = `which tj3`.strip
|
|
85
|
+
return path unless path.empty?
|
|
86
|
+
|
|
87
|
+
raise "TaskJuggler executable not found"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: taskjuggler-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nathan Kidd
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 8.0.2
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 8.0.2
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: taskjuggler
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.8'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.8'
|
|
40
|
+
description: Render Taskjuggler files (.tjp) as controller views.
|
|
41
|
+
email:
|
|
42
|
+
- nathankidd@hey.com
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- LICENSE
|
|
48
|
+
- README.md
|
|
49
|
+
- lib/taskjuggler-rails.rb
|
|
50
|
+
- lib/taskjuggler_rails/engine.rb
|
|
51
|
+
- lib/taskjuggler_rails/renderer.rb
|
|
52
|
+
- lib/taskjuggler_rails/version.rb
|
|
53
|
+
homepage: https://github.com/n-at-han-k/taskjuggler-rails
|
|
54
|
+
licenses: []
|
|
55
|
+
metadata:
|
|
56
|
+
homepage_uri: https://github.com/n-at-han-k/taskjuggler-rails
|
|
57
|
+
source_code_uri: https://github.com/n-at-han-k/taskjuggler-rails
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
require_paths:
|
|
60
|
+
- lib
|
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
requirements: []
|
|
72
|
+
rubygems_version: 3.6.9
|
|
73
|
+
specification_version: 4
|
|
74
|
+
summary: Render Taskjuggler files (.tjp) as controller views.
|
|
75
|
+
test_files: []
|