rgtk 0.0.3

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ doc
20
+ pkg
21
+
22
+ ## PROJECT::SPECIFIC
data/.yardoc ADDED
Binary file
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alexander Semyonov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ = rgtk
2
+
3
+ Rgtk is a small but sweet Ruby GTK framework, that uses MVC concept
4
+ and try to be more native to ruby and GTK than Rugui.
5
+
6
+ == Features
7
+ * nice DSL to adding signal callbacks
8
+ * Automatically builds Gtk::AboutDialog from gemspec of current application
9
+
10
+ == Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but
18
+ bump version in a commit by itself I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Copyright
22
+
23
+ Copyright © 2009 Alexander Semyonov. See LICENSE for details.
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'rgtk'
8
+ gem.summary = %Q{Small framework for Ruby GTK development}
9
+ gem.description = %Q{Rails-flavoured Ruby GTK framework}
10
+ gem.email = 'rotuka@tokak.ru'
11
+ gem.homepage = 'http://github.com/rotuka/rgtk'
12
+ gem.authors = ['Alexander Semyonov']
13
+ gem.add_development_dependency 'thoughtbot-shoulda', '>= 0'
14
+ gem.add_development_dependency 'yard', '>= 0'
15
+ gem.add_dependency 'activesupport', '>= 2.3.4'
16
+ gem.add_dependency 'xdg', '0.5.2'
17
+ gem.add_dependency 'ya2yaml'
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ begin
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new
51
+ rescue LoadError
52
+ task :yardoc do
53
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
54
+ end
55
+ end
56
+
57
+ desc "Bump gem version, release and install"
58
+ task :push => %w(version:bump:patch release gemcutter:release install)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,10 @@
1
+ require 'activesupport'
2
+ $KCODE = 'UTF-8'
3
+
4
+ module Rgtk
5
+ mattr_accessor :root
6
+ end
7
+
8
+ require 'rgtk/app'
9
+ require 'rgtk/config'
10
+ require 'rgtk/controller'
@@ -0,0 +1,113 @@
1
+ require 'singleton'
2
+ require 'xdg'
3
+ require 'activesupport'
4
+
5
+ module Rgtk
6
+ class App
7
+ include Singleton
8
+
9
+ def initialize
10
+ @name = self.class.name
11
+ @controllers = {}
12
+ @loggers = {}
13
+ extend_load_path
14
+ end
15
+
16
+ def root
17
+ Rgtk.root
18
+ end
19
+
20
+ def app_name
21
+ @app_name ||= self.class.name.underscore.gsub(/_app/, '')
22
+ end
23
+
24
+ def run
25
+ Gtk.init
26
+ load_models
27
+ load_controllers
28
+ if defined?(:MainController)
29
+ @controllers[:main] = MainController.new
30
+ @controllers[:main].run
31
+ end
32
+ Gtk.main
33
+ end
34
+
35
+ def extend_load_path
36
+ $LOAD_PATH.unshift(controllers_dir)
37
+ $LOAD_PATH.unshift(models_dir)
38
+ end
39
+
40
+ def load_controllers
41
+ Dir[File.join(controllers_dir, '**', '*')].each do |controller_file_name|
42
+ controller_name = File.basename(controller_file_name, '.rb')
43
+ require controller_name
44
+ end
45
+ end
46
+
47
+ def load_models
48
+ connect_db if config.use_db?
49
+ Dir[File.join(models_dir, '**', '*')].each do |model_file_name|
50
+ model_name = File.basename(model_file_name, '.rb')
51
+ require model_name
52
+ end
53
+ end
54
+
55
+ %w(models views controllers).each do |mvc|
56
+ class_eval <<-END_SRC, __FILE__, __LINE__
57
+ def #{mvc}_dir
58
+ @#{mvc}_dir ||= File.join(Rgtk.root, 'app', '#{mvc}')
59
+ end
60
+ END_SRC
61
+ end
62
+
63
+ def config
64
+ unless @config
65
+ @config = Rgtk::Config.new
66
+ end
67
+ @config
68
+ end
69
+
70
+ def logger(kind = :application)
71
+ @loggers[kind] ||= Logger.new(File.open(data_file("#{kind}.log"), 'a'))
72
+ end
73
+
74
+ def connect_db
75
+ require 'activerecord'
76
+ config.database ||= {:adapter => 'sqlite3',
77
+ :database => data_file("#{app_name}.sqlite3")}
78
+ ActiveRecord::Base.establish_connection(config.database.symbolize_keys!)
79
+ ActiveRecord::Base.logger = logger(:database)
80
+ end
81
+
82
+ %w(config data cache).each do |kind|
83
+ class_eval <<-END_SRC, __FILE__, __LINE__
84
+ def #{kind}_dir # def config_dir
85
+ @#{kind}_dir ||= xdg_dir(:#{kind}) # @confid_dir ||= xdg_dir(:config)
86
+ end # end
87
+
88
+ def #{kind}_file(file_name) # def config_file(file_name)
89
+ File.join(#{kind}_dir, file_name) # File.join(config_dir, file_name)
90
+ end # end
91
+ END_SRC
92
+ end
93
+
94
+ def destroy
95
+ config.save! unless config.autosave? == false
96
+ Gtk.main_quit
97
+ end
98
+
99
+ protected
100
+ # Return xdg dir, autocreate if it does not present
101
+ # @param [String] :config, :data or :cache - kind of xdg dir
102
+ def xdg_dir(kind)
103
+ dirs = XDG.send(:"#{kind}_select", app_name)
104
+ if dirs.empty?
105
+ returning(File.join(XDG.send(:"#{kind}_home"), app_name)) do |dir_name|
106
+ Dir.mkdir(dir_name)
107
+ end
108
+ else
109
+ dirs.first
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,33 @@
1
+ module Rgtk
2
+ class Config
3
+ def initialize(file_name = 'config.yml')
4
+ @file_name = File.join(::App.config_dir, file_name)
5
+ @config = if File.exists?(@file_name)
6
+ YAML.load_file(@file_name) || {}
7
+ else
8
+ `touch #{@file_name}`
9
+ {}
10
+ end.to_hash.with_indifferent_access
11
+ end
12
+
13
+ def method_missing(method_name, *args)
14
+ if method_name.to_s =~ /^([a-z0-9_]+)=$/
15
+ @config[$1] = args.first
16
+ else
17
+ @config[method_name]
18
+ end
19
+ end
20
+
21
+ def [](name)
22
+ @config[name]
23
+ end
24
+
25
+ def []=(name, value)
26
+ @config[name] = value
27
+ end
28
+
29
+ def save!
30
+ File.open(@file_name, 'w') { |f| f.write(@config.to_yaml) }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'activesupport'
2
+ require 'gtk2'
3
+
4
+ module Rgtk
5
+ module Controller
6
+ end
7
+ end
8
+
9
+ require 'rgtk/controller/dsl'
10
+ require 'rgtk/controller/base'
11
+ require 'rgtk/controller/about'
@@ -0,0 +1,34 @@
1
+ module Rgtk
2
+ module Controller
3
+ class About
4
+ def dialog
5
+ unless @dialog
6
+ @dialog = Gtk::AboutDialog.new
7
+ @gem_name = ::App.app_name
8
+
9
+ gem @gem_name
10
+ @spec = Gem.loaded_specs[@gem_name]
11
+
12
+ @dialog.program_name = @spec.summary
13
+ @dialog.comments = @spec.description
14
+ @dialog.version = @spec.version.to_s
15
+ @dialog.website = @spec.homepage
16
+ @dialog.authors = [@spec.author]
17
+
18
+ @dialog.signal_connect('response') do |dialog, button|
19
+ dialog.hide if button == Gtk::Dialog::RESPONSE_CANCEL
20
+ end
21
+ end
22
+ @dialog
23
+ end
24
+
25
+ def show
26
+ dialog.show
27
+ end
28
+
29
+ def hide
30
+ dialog.hide
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ module Rgtk
2
+ module Controller
3
+ class Base
4
+ extend Rgtk::Controller::DSL
5
+ attr_accessor :builder, :view_name, :objects
6
+
7
+ def self.controller_name
8
+ self.name.underscore.sub(/_controller$/, '')
9
+ end
10
+
11
+ def controller_name
12
+ @_controller_name
13
+ end
14
+
15
+ def controller_name=(name)
16
+ @_controller_name = name
17
+ end
18
+
19
+ def initialize
20
+ @_controller_name ||= self.class.controller_name
21
+ load_objects
22
+ end
23
+
24
+ def run
25
+ container.show
26
+ end
27
+
28
+ def [](object_name)
29
+ @_children[object_name.to_s]
30
+ end
31
+
32
+ def method_missing(method_name, *args)
33
+ if @_children.key?(method_name)
34
+ self[method_name]
35
+ else
36
+ super(method_name, *args)
37
+ end
38
+ end
39
+
40
+ protected
41
+ # Main view container
42
+ # @return [Gtk::Container] conventionally named container
43
+ def container
44
+ self[:container]
45
+ end
46
+
47
+ # Find the view name from controller name
48
+ # @return [String] full path to view name
49
+ def view_name
50
+ unless @_view_name
51
+ self.view_name = controller_name
52
+ end
53
+ @_view_name
54
+ end
55
+
56
+ # Set the view name if it does not match controller’s one
57
+ # @param [String] view name without path and ".ui" extension
58
+ # @return [String] full path to view name
59
+ def view_name=(view_name)
60
+ @_view_name = File.join(::App.views_dir, "#{view_name}.ui")
61
+ raise "Error: no view provided for #{self.class.name} (should be in #{@_view_name})" unless File.exists?(@_view_name)
62
+ end
63
+
64
+ # Initialize (if doesn’t) and return builder for controller
65
+ # @return [Gtk::Builder] actual builder
66
+ def builder
67
+ unless @_builder
68
+ @_builder = Gtk::Builder.new
69
+ @_builder << view_name
70
+ @_builder.connect_signals do |handler|
71
+ method(handler)
72
+ end
73
+ end
74
+ @_builder
75
+ end
76
+
77
+ def load_objects
78
+ @_children = builder.objects.inject({}) do |children, object|
79
+ children[object.name.sub(/^#{controller_name}_/, '')] = object
80
+ children
81
+ end.with_indifferent_access
82
+ end
83
+
84
+ def flunk(message = "Flunked")
85
+ puts message
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ module Rgtk
2
+ module Controller
3
+ module DSL
4
+ def shortcuts(shortcut_hash)
5
+ shortcut_hash.each do |key, name|
6
+ define_method key do
7
+ builder.get_object(name)
8
+ end
9
+ end
10
+ end
11
+
12
+ def signals_for(object)
13
+ _current_object.push(object)
14
+ yield
15
+ _current_object.pop
16
+ end
17
+
18
+ def on(action, &block)
19
+ callback_name = "#{signal_prefix}_#{action}"
20
+ defined = instance_method(callback_name) rescue false
21
+ raise "#{callback_name} is already defined in #{self}" if defined
22
+ if block_given?
23
+ define_method(callback_name, &block)
24
+ else
25
+ define_method(callback_name) do
26
+ flunk "No implementation provided for #{callback_name}"
27
+ end
28
+ end
29
+ end
30
+ alias_method :signal, :on
31
+
32
+ %w(activate toggled changed).each do |signal|
33
+ class_eval <<-END_SRC, __FILE__, __LINE__
34
+ def #{signal}(object_name, &block)
35
+ on("\#{object_name}_#{signal}", &block)
36
+ end
37
+ END_SRC
38
+ end
39
+
40
+ protected
41
+ def signal_prefix
42
+ if _current_object.empty?
43
+ 'on'
44
+ else
45
+ "on_#{_current_object.join('_')}"
46
+ end
47
+ end
48
+
49
+ def _current_object
50
+ @_current_object ||= []
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rgtk}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Semyonov"]
12
+ s.date = %q{2009-11-11}
13
+ s.description = %q{Rails-flavoured Ruby GTK framework}
14
+ s.email = %q{rotuka@tokak.ru}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".yardoc",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/rgtk.rb",
28
+ "lib/rgtk/app.rb",
29
+ "lib/rgtk/config.rb",
30
+ "lib/rgtk/controller.rb",
31
+ "lib/rgtk/controller/about.rb",
32
+ "lib/rgtk/controller/base.rb",
33
+ "lib/rgtk/controller/dsl.rb",
34
+ "rgtk.gemspec",
35
+ "test/helper.rb",
36
+ "test/test_rgtk.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/rotuka/rgtk}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{Small framework for Ruby GTK development}
43
+ s.test_files = [
44
+ "test/helper.rb",
45
+ "test/test_rgtk.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<yard>, [">= 0"])
55
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
56
+ s.add_runtime_dependency(%q<xdg>, ["= 0.5.2"])
57
+ s.add_runtime_dependency(%q<ya2yaml>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<yard>, [">= 0"])
61
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
62
+ s.add_dependency(%q<xdg>, ["= 0.5.2"])
63
+ s.add_dependency(%q<ya2yaml>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
67
+ s.add_dependency(%q<yard>, [">= 0"])
68
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
69
+ s.add_dependency(%q<xdg>, ["= 0.5.2"])
70
+ s.add_dependency(%q<ya2yaml>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rgtk'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRgtk < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgtk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Semyonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-11 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.3.4
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: xdg
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.2
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: ya2yaml
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ description: Rails-flavoured Ruby GTK framework
66
+ email: rotuka@tokak.ru
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - .yardoc
78
+ - LICENSE
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - lib/rgtk.rb
83
+ - lib/rgtk/app.rb
84
+ - lib/rgtk/config.rb
85
+ - lib/rgtk/controller.rb
86
+ - lib/rgtk/controller/about.rb
87
+ - lib/rgtk/controller/base.rb
88
+ - lib/rgtk/controller/dsl.rb
89
+ - rgtk.gemspec
90
+ - test/helper.rb
91
+ - test/test_rgtk.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/rotuka/rgtk
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --charset=UTF-8
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.5
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Small framework for Ruby GTK development
120
+ test_files:
121
+ - test/helper.rb
122
+ - test/test_rgtk.rb