Skip to content

Commit 1d3dfa1

Browse files
committed
Using erb template for config.geany
1 parent 25738ff commit 1d3dfa1

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'project.build.sourceEncoding' => 'utf-8',
3232
'polyglot.dump.pom' => 'pom.xml')
3333

34-
pom 'org.jruby:jruby:9.2.11.0'
34+
pom 'org.jruby:jruby:9.2.12.0'
3535
jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
3636
jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
3737
jar 'org.processing:video:3.0.2'

vendors/Rakefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'fileutils'
44
require 'rake/clean'
5+
relative_require 'geany'
56
WARNING = 'WARNING: wget download failed you could do a manual download'
67
SOUND = 'sound.zip'
78
SOUND_VERSION = 'v1.3.2'
@@ -69,9 +70,11 @@ task :install_config do
6970
FileUtils.mkdir_p "#{HOME_DIR}/.config/geany/templates/files"
7071
FileUtils.cp 'picrate.rb', "#{HOME_DIR}/.config/geany/templates/files"
7172
end
72-
unless File.exist? "#{HOME_DIR}/projects/sketchbook/picrate_sketches.geany"
73-
FileUtils.mkdir_p "#{HOME_DIR}/projects/sketchbook"
74-
FileUtils.cp 'picrate_sketches.geany', "#{HOME_DIR}/projects/sketchbook"
73+
project_dir = File.join(HOME_DIR, 'projects')
74+
unless File.exist? File.join(project_dir, 'examples', 'picrate_sketches.geany')
75+
FileUtils.mkdir_p "#{HOME_DIR}/projects/examples"
76+
config = GeanyConfig.new(project_dir, 'examples')
77+
config.save(File.join(project_dir, 'examples', 'picrate_sketches.geany'))"
7578
end
7679
end
7780
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require 'erb'
4+
5+
def geany_config
6+
%(
17
[editor]
28
line_wrapping=false
39
line_break_column=72
@@ -19,7 +25,7 @@
1925
2026
[project]
2127
name=picrate_samples
22-
base_path=/home/pi/projects/picrate_sketches
28+
base_path=<%= home %>
2329
description=Exploring PiCrate
2430
file_patterns=*.rb;*.glsl;*.txt;
2531
@@ -28,14 +34,9 @@
2834
long_line_column=72
2935
3036
[files]
31-
current_page=3
32-
FILE_NAME_0=667;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fbasics%2Farrays%2Farray.rb;0;2
33-
FILE_NAME_1=1664;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fadvanced_data%2Fload_save_json.rb;0;2
34-
FILE_NAME_2=259;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fjruby_install.sh;0;2
35-
FILE_NAME_3=236;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Ftest.sh;0;2
3637
3738
[VTE]
38-
last_dir=/home/pi
39+
last_dir=<%= directory %>
3940
4041
[build-menu]
4142
EX_00_LB=_Execute
@@ -60,3 +61,27 @@
6061
RubyFT_02_LB=_Reek
6162
RubyFT_02_CM=reek --failure-exit-code=0 "%f"
6263
RubyFT_02_WD=
64+
)
65+
end
66+
67+
# Class to merge ERB template and write config to file
68+
class GeanyConfig
69+
include ERB::Util
70+
attr_accessor :home, :directory, :template
71+
72+
def initialize(home, directory, template = geany_config)
73+
@home = home
74+
@directory = File.join(home, directory)
75+
@template = template
76+
end
77+
78+
def render
79+
ERB.new(@template).result(binding)
80+
end
81+
82+
def save(file)
83+
File.open(file, 'w+') do |f|
84+
f.write(render)
85+
end
86+
end
87+
end

0 commit comments

Comments
 (0)