skema 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ == 0.2.0 05/03/2008
2
+
3
+ * Packaged skema as a gem
4
+ * Added LGPL template
5
+
6
+ == 0.1 19/11/2007
7
+
8
+ * First release
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2007-2008 Paolo Capriotti <p.capriotti@gmail.com>
2
+ Copyright (c) 2008 Riccardo Iaconelli <riccardo@kde.org>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/skema
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ lib/modules/gpl/gpl.rb
10
+ lib/modules/gpl/templates/file
11
+ lib/modules/kapp/kapp.rb
12
+ lib/modules/kapp/templates/CMakeLists.txt
13
+ lib/modules/kapp/templates/appui.rc
14
+ lib/modules/kapp/templates/main.cpp
15
+ lib/modules/lgpl/lgpl.rb
16
+ lib/modules/lgpl/templates/file
17
+ lib/modules/skemaconfig/skemaconfig.rb
18
+ lib/modules/skemaconfig/templates/skemarc
19
+ lib/skema.rb
20
+ lib/skema/version.rb
21
+ script/destroy
22
+ script/generate
23
+ script/txt2html
24
+ setup.rb
25
+ tasks/deployment.rake
26
+ tasks/environment.rake
27
+ tasks/website.rake
28
+ test/test_helper.rb
29
+ test/test_skema.rb
30
+ website/img/header_bg.png
31
+ website/index.html
32
+ website/index.txt
33
+ website/javascripts/rounded_corners_lite.inc.js
34
+ website/stylesheets/screen.css
35
+ website/template.rhtml
@@ -0,0 +1,17 @@
1
+ = skema
2
+
3
+ === A command line template expansion tool
4
+
5
+ Homepage: http://skema.rubyforge.org/
6
+
7
+ Copyright (c) 2008 Paolo Capriotti <p.capriotti@gmail.com>
8
+
9
+ skema is a command line utility for expanding templates.
10
+ It can be used in a number of ways. Examples include:
11
+ * fast prototyping applications in frameworks that require a lot of boilerplate code;
12
+ * adding copyright statements to source files;
13
+ * automating repetitive coding tasks.
14
+
15
+ Of course, there's nothing in skema that you can't find in your favourite text
16
+ editor's templating facility; skema just makes it easier if you happen to like
17
+ the command line.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # skema - A command line template expansion tool
4
+ #
5
+ # Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to
12
+ # permit persons to whom the Software is furnished to do so, subject to
13
+ # the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be
16
+ # included in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ require 'rubygems' rescue nil
27
+ require 'skema'
28
+
29
+ def error(msg)
30
+ warn "ERROR: #{msg}"
31
+ exit 1
32
+ end
33
+
34
+ def usage
35
+ error "Usage #$0 MODULE TARGET [ARGS...]"
36
+ end
37
+
38
+ def load_module(mod)
39
+ alt = [mod]
40
+ mdir = Skema::config[:skema_modules_dir]
41
+ case mdir
42
+ when String
43
+ alt << File.join(mdir, mod)
44
+ when Array
45
+ mdir.each do |module_dir|
46
+ alt << File.join(module_dir, mod)
47
+ end
48
+ end
49
+ alt = alt.inject([]) do |res, file|
50
+ if File.exist? file
51
+ if File.directory? file
52
+ modfile = File.join(file, "#{File.basename(file)}.rb")
53
+ if File.exist? modfile
54
+ res << modfile
55
+ else
56
+ # add all ruby scripts
57
+ Dir[File.join(file, '*.rb')].each do |modfile|
58
+ res << modfile
59
+ end
60
+ end
61
+ else
62
+ res << file
63
+ end
64
+ end
65
+ res
66
+ end
67
+
68
+ alt.each do |file|
69
+ begin
70
+ load file
71
+ return file
72
+ rescue Exception => e
73
+ warn "Could not load #{file}:"
74
+ warn e
75
+ end
76
+ end
77
+ error "Could not load module #{mod}. Tried #{alt.join ','}"
78
+ end
79
+
80
+ def ask(key, value)
81
+ ans = nil
82
+ while ans.nil? || ans.empty?
83
+ q = key.to_s
84
+ q += " [#{value}]" if value
85
+ q += ": "
86
+ $stdout.write(q)
87
+ ans = $stdin.gets.chomp
88
+ ans = value if ans.empty?
89
+ end
90
+ ans
91
+ end
92
+
93
+ mod = ARGV.shift or usage
94
+ if mod == "-i"
95
+ $interactive = true
96
+ mod = ARGV.shift or usage
97
+ end
98
+ target = ARGV.shift or usage
99
+ mod = load_module mod
100
+ error "Invalid template module" unless $last_template
101
+
102
+ # read args
103
+ args = {}
104
+ if File.exist?(target) and not File.directory?(target)
105
+ args[:filename] = File.basename(target)
106
+ target = File.dirname(target)
107
+ end
108
+ ARGV.each do |arg|
109
+ if arg =~ /^(\S*):(.*)$/
110
+ args[$1.to_sym] = $2
111
+ else
112
+ usage
113
+ end
114
+ end
115
+
116
+ $last_template.args.each do |key, value|
117
+ unless args.has_key? key
118
+ default = nil
119
+ if not value.nil?
120
+ default = value
121
+ elsif Skema::config.has_key? key
122
+ default = Skema::config[key]
123
+ end
124
+
125
+ if $interactive || Skema::config[:interactive]
126
+ args[key] = ask(key, default)
127
+ elsif default
128
+ args[key] = default
129
+ else
130
+ error "Missing argument #{key}"
131
+ end
132
+ end
133
+ end
134
+
135
+ dir = $last_template.template || File.dirname(mod)
136
+ template = Skema::Template.new dir, target
137
+ template.run args
@@ -0,0 +1,70 @@
1
+ require 'skema/version'
2
+
3
+ AUTHOR = 'Paolo Capriotti'
4
+ EMAIL = "p.capriotti@gmail.com"
5
+ DESCRIPTION = "Command line template expansion tool"
6
+ GEM_NAME = 'skema'
7
+ RUBYFORGE_PROJECT = 'skema'
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "pcapriotti"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Skema::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'skema documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'skema'
@@ -0,0 +1,4 @@
1
+ template :author => nil,
2
+ :email => nil,
3
+ :year => Time.now.year,
4
+ :filename => nil
@@ -0,0 +1,10 @@
1
+ <% filename @filename %>/*
2
+ Copyright (c) <%= @year %> <%= @author %> <<%= @email %>>
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ */
9
+
10
+ <%= original_content %>
@@ -0,0 +1,6 @@
1
+ template :name => nil,
2
+ :title => nil,
3
+ :version => "0.1",
4
+ :author => nil,
5
+ :email => nil
6
+
@@ -0,0 +1,17 @@
1
+ project(<%= @name %>)
2
+
3
+ find_package(KDE4)
4
+ include(KDE4Defaults)
5
+
6
+ set(<%= @name %>_SRC
7
+ main.cpp
8
+ )
9
+
10
+ include_directories(${KDE4_INCLUDES})
11
+
12
+ kde4_add_executable(<%= @name %> ${<%= @name %>_SRC})
13
+ target_link_libraries(<%= @name %> ${KDE4_KDEUI_LIBS})
14
+
15
+ install(TARGETS <%= @name %> DESTINATION ${BIN_INSTALL_DIR})
16
+ # install(FILES <%= @name %>.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
17
+ install(FILES <%= @name %>ui.rc DESTINATION ${DATA_INSTALL_DIR}/<%= @name %>)
@@ -0,0 +1,5 @@
1
+ <% filename "#{@name}ui.rc" %>
2
+ <?xml version="1.0" encoding="utf-8"?>
3
+ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
4
+ <gui name="<%= @name %>" version="1">
5
+ </gui>
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright (c) <%= Time.now.year %> <%= @author %> <<%= @email %>>
3
+
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+ */
10
+
11
+ #include <KApplication>
12
+ #include <KAboutData>
13
+ #include <KLocale>
14
+ #include <KCmdLineArgs>
15
+
16
+ int main(int argc, char *argv[])
17
+ {
18
+ KAboutData aboutData("<%= @name %>", 0, ki18n("<%= @title %>"),
19
+ "<%= @version %>", ki18n("Description"),
20
+ KAboutData::License_GPL,
21
+ ki18n("(c) <%= Time.now.year %> <%= @author %>"),
22
+ KLocalizedString(), "", "<%= @email %>");
23
+ aboutData.addAuthor(ki18n("<%= @author %>"), KLocalizedString(), "<%= @email %>");
24
+
25
+ KCmdLineArgs::init(argc, argv, &aboutData);
26
+
27
+ KCmdLineOptions options;
28
+ KCmdLineArgs::addCmdLineOptions(options);
29
+ KCmdLineArgs::parsedArgs();
30
+ KApplication app;
31
+
32
+ return app.exec();
33
+ }
34
+
@@ -0,0 +1,4 @@
1
+ template :author => nil,
2
+ :email => nil,
3
+ :year => Time.now.year,
4
+ :filename => nil
@@ -0,0 +1,19 @@
1
+ <% filename @filename %>/*
2
+ Copyright (c) <%= @year %> <%= @author %> <<%= @email %>>
3
+
4
+ This library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License version 2 as published by the Free Software Foundation.
7
+
8
+ This library is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ Lesser General Public License for more details.
12
+
13
+ You should have received a copy of the GNU Lesser General Public License
14
+ along with this library; see the file COPYING.LIB. If not, write to
15
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
+ Boston, MA 02110-1301, USA.
17
+ */
18
+
19
+ <%= original_content %>
@@ -0,0 +1 @@
1
+ template :name => nil, :email => nil, :filename => nil
@@ -0,0 +1,5 @@
1
+ <% filename @filename %>:author: <%= @name %>
2
+ :email: <%= @email %>
3
+ :skema_modules_dir:
4
+ - <%= File.join(ENV['HOME'], '.skema') %>
5
+
@@ -0,0 +1,122 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'find'
3
+ require 'fileutils'
4
+ require 'erb'
5
+ require 'yaml'
6
+
7
+ def template(*args)
8
+ dirname = nil
9
+ dirname = args.first if args.size > 1
10
+ args = args.last || {}
11
+
12
+ $last_template = Skema::TemplateDefinition.new(dirname, args)
13
+ end
14
+
15
+ module Skema
16
+ DEFAULT_MODULE_DIR = File.join(File.dirname(__FILE__), 'modules')
17
+
18
+ def self.config
19
+ @@config ||= Config.new
20
+ end
21
+
22
+ def self.last
23
+ @@last
24
+ end
25
+
26
+ class Config
27
+ def initialize
28
+ configfile = File.join(ENV['HOME'], '.skemarc')
29
+ if File.exist? configfile
30
+ @config = File.open(configfile) {|f| YAML::load(f) }
31
+ else
32
+ @config = {}
33
+ end
34
+ md = @config[:skema_modules_dir] ||= []
35
+ md.unshift(DEFAULT_MODULE_DIR) if md.class == Array
36
+ end
37
+
38
+ def [](key)
39
+ @config[key]
40
+ end
41
+
42
+ def has_key? key
43
+ @config.has_key? key
44
+ end
45
+ end
46
+
47
+ class TemplateDefinition
48
+ attr_reader :template, :args
49
+ def initialize(template, args)
50
+ @template = template
51
+ @args = args
52
+ end
53
+ end
54
+
55
+ class Template
56
+ def initialize(dir, target)
57
+ @dir = dir
58
+ @target = target
59
+ end
60
+
61
+ def run(arguments)
62
+ template_dir = File.join(@dir, 'templates')
63
+ if File.exists? template_dir
64
+ Find.find(template_dir) do |filename|
65
+ Find.purge if filename[0] == '.'
66
+ next if File.directory? filename
67
+ args = Args.new(@target, filename[template_dir.size+1..-1], arguments)
68
+ data = File.open(filename) do |f|
69
+ ERB.new(f.read).result(args.get_binding)
70
+ end
71
+ puts "-> #{args.filename}"
72
+ create_file(args.full_filename, data)
73
+ end
74
+ end
75
+ end
76
+
77
+ def create_file(filename, data)
78
+ dir = File.dirname filename
79
+ FileUtils.mkdir_p dir unless File.exist? dir
80
+ File.open(filename, 'w') {|f| f.write data }
81
+ end
82
+ end
83
+
84
+ class Args
85
+ def initialize(target, base, args)
86
+ @_target = target
87
+ @_base = base
88
+ args.each do |arg, value|
89
+ instance_variable_set("@#{arg}", value)
90
+ end
91
+ end
92
+
93
+ def get_binding
94
+ binding
95
+ end
96
+
97
+ def filename(*args)
98
+ if args.size > 0
99
+ filename = args.shift
100
+ @_filename = if args.include? :absolute
101
+ filename
102
+ else
103
+ File.join(File.dirname(@_base), filename)
104
+ end
105
+ else
106
+ @_filename || @_base
107
+ end
108
+ end
109
+
110
+ def full_filename
111
+ File.join(@_target, filename)
112
+ end
113
+
114
+ def original_content
115
+ if File.exist? full_filename
116
+ File.open(full_filename) {|f| f.read }
117
+ else
118
+ ""
119
+ end
120
+ end
121
+ end
122
+ end