ironnails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/ironnails.gemspec +96 -0
- data/lib/iron_nails.rb +1 -0
- data/lib/ironnails/bin/IronNails.Library.dll +0 -0
- data/lib/ironnails/bin/IronRuby.Libraries.Yaml.dll +0 -0
- data/lib/ironnails/bin/IronRuby.Libraries.dll +0 -0
- data/lib/ironnails/bin/IronRuby.dll +0 -0
- data/lib/ironnails/bin/Microsoft.Dynamic.dll +0 -0
- data/lib/ironnails/bin/Microsoft.Scripting.Core.dll +0 -0
- data/lib/ironnails/bin/Microsoft.Scripting.ExtensionAttribute.dll +0 -0
- data/lib/ironnails/bin/Microsoft.Scripting.dll +0 -0
- data/lib/ironnails/config/configuration.rb +141 -0
- data/lib/ironnails/config/initializer.rb +144 -0
- data/lib/ironnails/controller/base.rb +135 -0
- data/lib/ironnails/controller/view_operations.rb +101 -0
- data/lib/ironnails/controller.rb +2 -0
- data/lib/ironnails/core_ext/array.rb +15 -0
- data/lib/ironnails/core_ext/class/attribute_accessors.rb +57 -0
- data/lib/ironnails/core_ext/class.rb +8 -0
- data/lib/ironnails/core_ext/fixnum.rb +22 -0
- data/lib/ironnails/core_ext/hash.rb +32 -0
- data/lib/ironnails/core_ext/kernel.rb +26 -0
- data/lib/ironnails/core_ext/string.rb +58 -0
- data/lib/ironnails/core_ext/symbol.rb +78 -0
- data/lib/ironnails/core_ext/system/net/web_request.rb +110 -0
- data/lib/ironnails/core_ext/system/security/secure_string.rb +18 -0
- data/lib/ironnails/core_ext/system/windows/markup/xaml_reader.rb +6 -0
- data/lib/ironnails/core_ext/system/windows/ui_element.rb +17 -0
- data/lib/ironnails/core_ext/time.rb +28 -0
- data/lib/ironnails/core_ext.rb +12 -0
- data/lib/ironnails/errors.rb +19 -0
- data/lib/ironnails/iron_xml.rb +83 -0
- data/lib/ironnails/logger.rb +4 -0
- data/lib/ironnails/logging/buffered_logger.rb +137 -0
- data/lib/ironnails/logging/class_logger.rb +29 -0
- data/lib/ironnails/models/base.rb +16 -0
- data/lib/ironnails/models/bindable_collection.rb +15 -0
- data/lib/ironnails/models/model_mixin.rb +69 -0
- data/lib/ironnails/models.rb +3 -0
- data/lib/ironnails/nails_engine.rb +398 -0
- data/lib/ironnails/observable.rb +117 -0
- data/lib/ironnails/security/secure_string.rb +61 -0
- data/lib/ironnails/version.rb +11 -0
- data/lib/ironnails/view/collections.rb +117 -0
- data/lib/ironnails/view/commands/add_sub_view_command.rb +33 -0
- data/lib/ironnails/view/commands/behavior_command.rb +29 -0
- data/lib/ironnails/view/commands/command.rb +208 -0
- data/lib/ironnails/view/commands/event_command.rb +32 -0
- data/lib/ironnails/view/commands/timed_command.rb +40 -0
- data/lib/ironnails/view/commands.rb +5 -0
- data/lib/ironnails/view/view.rb +190 -0
- data/lib/ironnails/view/view_model.rb +45 -0
- data/lib/ironnails/view/xaml_proxy.rb +226 -0
- data/lib/ironnails/view.rb +5 -0
- data/lib/ironnails/wpf.rb +113 -0
- data/lib/ironnails/wpf_application.rb +30 -0
- data/lib/ironnails.rb +68 -0
- metadata +133 -0
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ironnails"
|
8
|
+
gem.summary = %Q{IronNails brings rails like development to IronRuby and WPF}
|
9
|
+
gem.description = %Q{IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing
|
10
|
+
applications with IronRuby and Windows Presentation Foundation (WPF).}
|
11
|
+
gem.email = "ivan@flanders.co.nz"
|
12
|
+
gem.homepage = "http://github.com/casualjim/ironnails"
|
13
|
+
gem.authors = ["Ivan Porto Carrero"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 0"
|
15
|
+
gem.files = FileList["[A-Z]*", "{lib}/**/*"]
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/ironnails"
|
data/ironnails.gemspec
ADDED
@@ -0,0 +1,96 @@
|
|
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{ironnails}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ivan Porto Carrero"]
|
12
|
+
s.date = %q{2010-02-28}
|
13
|
+
s.description = %q{IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing
|
14
|
+
applications with IronRuby and Windows Presentation Foundation (WPF).}
|
15
|
+
s.email = %q{ivan@flanders.co.nz}
|
16
|
+
s.files = [
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"init.rb",
|
20
|
+
"ironnails.gemspec",
|
21
|
+
"lib/iron_nails.rb",
|
22
|
+
"lib/ironnails.rb",
|
23
|
+
"lib/ironnails/bin/IronNails.Library.dll",
|
24
|
+
"lib/ironnails/bin/IronRuby.Libraries.Yaml.dll",
|
25
|
+
"lib/ironnails/bin/IronRuby.Libraries.dll",
|
26
|
+
"lib/ironnails/bin/IronRuby.dll",
|
27
|
+
"lib/ironnails/bin/Microsoft.Dynamic.dll",
|
28
|
+
"lib/ironnails/bin/Microsoft.Scripting.Core.dll",
|
29
|
+
"lib/ironnails/bin/Microsoft.Scripting.ExtensionAttribute.dll",
|
30
|
+
"lib/ironnails/bin/Microsoft.Scripting.dll",
|
31
|
+
"lib/ironnails/config/configuration.rb",
|
32
|
+
"lib/ironnails/config/initializer.rb",
|
33
|
+
"lib/ironnails/controller.rb",
|
34
|
+
"lib/ironnails/controller/base.rb",
|
35
|
+
"lib/ironnails/controller/view_operations.rb",
|
36
|
+
"lib/ironnails/core_ext.rb",
|
37
|
+
"lib/ironnails/core_ext/array.rb",
|
38
|
+
"lib/ironnails/core_ext/class.rb",
|
39
|
+
"lib/ironnails/core_ext/class/attribute_accessors.rb",
|
40
|
+
"lib/ironnails/core_ext/fixnum.rb",
|
41
|
+
"lib/ironnails/core_ext/hash.rb",
|
42
|
+
"lib/ironnails/core_ext/kernel.rb",
|
43
|
+
"lib/ironnails/core_ext/string.rb",
|
44
|
+
"lib/ironnails/core_ext/symbol.rb",
|
45
|
+
"lib/ironnails/core_ext/system/net/web_request.rb",
|
46
|
+
"lib/ironnails/core_ext/system/security/secure_string.rb",
|
47
|
+
"lib/ironnails/core_ext/system/windows/markup/xaml_reader.rb",
|
48
|
+
"lib/ironnails/core_ext/system/windows/ui_element.rb",
|
49
|
+
"lib/ironnails/core_ext/time.rb",
|
50
|
+
"lib/ironnails/errors.rb",
|
51
|
+
"lib/ironnails/iron_xml.rb",
|
52
|
+
"lib/ironnails/logger.rb",
|
53
|
+
"lib/ironnails/logging/buffered_logger.rb",
|
54
|
+
"lib/ironnails/logging/class_logger.rb",
|
55
|
+
"lib/ironnails/models.rb",
|
56
|
+
"lib/ironnails/models/base.rb",
|
57
|
+
"lib/ironnails/models/bindable_collection.rb",
|
58
|
+
"lib/ironnails/models/model_mixin.rb",
|
59
|
+
"lib/ironnails/nails_engine.rb",
|
60
|
+
"lib/ironnails/observable.rb",
|
61
|
+
"lib/ironnails/security/secure_string.rb",
|
62
|
+
"lib/ironnails/version.rb",
|
63
|
+
"lib/ironnails/view.rb",
|
64
|
+
"lib/ironnails/view/collections.rb",
|
65
|
+
"lib/ironnails/view/commands.rb",
|
66
|
+
"lib/ironnails/view/commands/add_sub_view_command.rb",
|
67
|
+
"lib/ironnails/view/commands/behavior_command.rb",
|
68
|
+
"lib/ironnails/view/commands/command.rb",
|
69
|
+
"lib/ironnails/view/commands/event_command.rb",
|
70
|
+
"lib/ironnails/view/commands/timed_command.rb",
|
71
|
+
"lib/ironnails/view/view.rb",
|
72
|
+
"lib/ironnails/view/view_model.rb",
|
73
|
+
"lib/ironnails/view/xaml_proxy.rb",
|
74
|
+
"lib/ironnails/wpf.rb",
|
75
|
+
"lib/ironnails/wpf_application.rb"
|
76
|
+
]
|
77
|
+
s.homepage = %q{http://github.com/casualjim/ironnails}
|
78
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
79
|
+
s.require_paths = ["lib"]
|
80
|
+
s.rubygems_version = %q{1.3.6}
|
81
|
+
s.summary = %q{IronNails brings rails like development to IronRuby and WPF}
|
82
|
+
|
83
|
+
if s.respond_to? :specification_version then
|
84
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
85
|
+
s.specification_version = 3
|
86
|
+
|
87
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
88
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
89
|
+
else
|
90
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
91
|
+
end
|
92
|
+
else
|
93
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
data/lib/iron_nails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/ironnails"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# A wrapper module that will contain all the relevant objects for our twitter application
|
2
|
+
module IronNails
|
3
|
+
|
4
|
+
# This structure has been heavily inspired by the rails framework.
|
5
|
+
# The Configuration class holds all the parameters for the Initializer
|
6
|
+
# Usually, you'll create a Configuration file implicitly through the block
|
7
|
+
# running on the Initializer, but it's also possible to create
|
8
|
+
# the Configuration instance in advance and pass it in
|
9
|
+
# like this:
|
10
|
+
#
|
11
|
+
# config = IronNails::Configuration.new
|
12
|
+
# IronNails::Initializer.run(config)
|
13
|
+
class Configuration
|
14
|
+
|
15
|
+
# the root path for our application
|
16
|
+
attr_reader :root_path
|
17
|
+
|
18
|
+
# the search paths for ruby source files
|
19
|
+
attr_reader :application_paths
|
20
|
+
|
21
|
+
# the search paths for .NET binaries
|
22
|
+
attr_reader :assembly_paths
|
23
|
+
|
24
|
+
# the namespaces that need to be included by default
|
25
|
+
attr_reader :namespaces
|
26
|
+
|
27
|
+
# the files that won't be initialized through this procedure
|
28
|
+
attr_reader :excluded_files
|
29
|
+
|
30
|
+
# The log level to use for the default Rails logger. In production mode,
|
31
|
+
# this defaults to <tt>:info</tt>. In development mode, it defaults to
|
32
|
+
# <tt>:debug</tt>.
|
33
|
+
attr_accessor :log_level
|
34
|
+
|
35
|
+
# The path to the log file to use. Defaults to log/#{environment}.log
|
36
|
+
# (e.g. log/development.log or log/production.log).
|
37
|
+
attr_accessor :log_path
|
38
|
+
|
39
|
+
# The specific logger to use. By default, a logger will be created and
|
40
|
+
# initialized using #log_path and #log_level, but a programmer may
|
41
|
+
# specifically set the logger to use via this accessor and it will be
|
42
|
+
# used directly.
|
43
|
+
attr_accessor :logger
|
44
|
+
|
45
|
+
def initialize(rpath = (File.dirname(__FILE__) + '/../../..'))
|
46
|
+
@root_path = rpath
|
47
|
+
initialize_with_defaults
|
48
|
+
end
|
49
|
+
|
50
|
+
def environment
|
51
|
+
::IRONNAILS_ENV
|
52
|
+
end
|
53
|
+
|
54
|
+
# The paths that contain sources for our application.
|
55
|
+
# We will require these at a later stage
|
56
|
+
def default_application_paths
|
57
|
+
paths = []
|
58
|
+
|
59
|
+
# Followed by the standard includes.
|
60
|
+
paths.concat %w(
|
61
|
+
config
|
62
|
+
lib
|
63
|
+
lib/core_ext
|
64
|
+
app
|
65
|
+
app/models
|
66
|
+
app/controllers
|
67
|
+
app/converters
|
68
|
+
app/helpers
|
69
|
+
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
70
|
+
end
|
71
|
+
|
72
|
+
#files to exclude from requiring in our app
|
73
|
+
def default_excluded_files
|
74
|
+
['config/environment.rb', 'lib/main.rb', 'config/boot.rb', 'bin/IronNails.Library.dll' ].collect{ |dir| "#{root_path}/#{dir}" }
|
75
|
+
end
|
76
|
+
|
77
|
+
def default_log_level
|
78
|
+
(IRONNAILS_ENV == 'development' || IRONNAILS_ENV.nil?) ? :debug : :info
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_log_path
|
82
|
+
File.join(root_path, 'log', "#{environment}.log")
|
83
|
+
end
|
84
|
+
|
85
|
+
# returns wheter or not the specified path is an excluded file
|
86
|
+
def excluded_file?(file_path)
|
87
|
+
excluded_files.include? file_path
|
88
|
+
end
|
89
|
+
|
90
|
+
# The paths that contain .NET binaries
|
91
|
+
def default_assembly_paths
|
92
|
+
paths = []
|
93
|
+
paths.concat %w( bin ).map{ |dir| "#{root_path}/#{dir}"}.select{ |dir| File.directory?(dir) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def default_namespaces
|
97
|
+
%w(
|
98
|
+
System
|
99
|
+
System::Net
|
100
|
+
System::Xml
|
101
|
+
System::IO
|
102
|
+
System::Web
|
103
|
+
System::Text
|
104
|
+
System::Threading
|
105
|
+
System::Windows
|
106
|
+
System::Collections::ObjectModel
|
107
|
+
IronNails::Controller
|
108
|
+
IronNails::View
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
def initialize_with_defaults
|
113
|
+
set_root_path!
|
114
|
+
@application_paths, @assembly_paths, @namespaces, @excluded_files = default_application_paths, default_assembly_paths, default_namespaces, default_excluded_files
|
115
|
+
@log_level, @log_path = default_log_level, default_log_path
|
116
|
+
end
|
117
|
+
|
118
|
+
# Set the root_path to IRONNAILS_ROOT and canonicalize it.
|
119
|
+
def set_root_path!
|
120
|
+
raise 'IRONNAILS_ROOT is not set' unless defined?(::IRONNAILS_ROOT)
|
121
|
+
raise 'IRONNAILS_ROOT is not a directory' unless File.directory?(::IRONNAILS_ROOT)
|
122
|
+
|
123
|
+
@root_path =
|
124
|
+
# Pathname is incompatible with Windows, but Windows doesn't have
|
125
|
+
# real symlinks so File.expand_path is safe.
|
126
|
+
if ENV['OS'] == 'Windows_NT'.freeze
|
127
|
+
File.expand_path(::IRONNAILS_ROOT)
|
128
|
+
|
129
|
+
# Otherwise use Pathname#realpath which respects symlinks.
|
130
|
+
else
|
131
|
+
Pathname.new(::IRONNAILS_ROOT).realpath.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
Object.const_set(:RELATIVE_SAILS_ROOT, ::IRONNAILS_ROOT.dup) unless defined?(::RELATIVE_SYLVESTER_ROOT)
|
135
|
+
|
136
|
+
::IRONNAILS_ROOT.replace @root_path
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
def include_global_namespaces(namespaces)
|
2
|
+
namespaces.each { |namespace| include(eval(namespace)) }
|
3
|
+
end
|
4
|
+
|
5
|
+
module IronNails
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# The Configuration instance used to configure the Rails environment
|
9
|
+
def configuration
|
10
|
+
@@configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def configuration=(configuration)
|
14
|
+
@@configuration = configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger
|
18
|
+
IRONNAILS_DEFAULT_LOGGER
|
19
|
+
end
|
20
|
+
|
21
|
+
def root
|
22
|
+
if defined?(IRONNAILS_ROOT)
|
23
|
+
IRONNAILS_ROOT
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def env
|
30
|
+
IRONNAILS_ENV
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
IronNails::VERSION::STRING
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# This structure has been heavily inspired by the rails framework.
|
40
|
+
# The Configuration class holds all the parameters for the Initializer
|
41
|
+
# Usually, you'll create a Configuration file implicitly through the block
|
42
|
+
# running on the Initializer, but it's also possible to create
|
43
|
+
# the Configuration instance in advance and pass it in
|
44
|
+
# like this:
|
45
|
+
#
|
46
|
+
# config = IronNails::Configuration.new
|
47
|
+
# IronNails::Initializer.run(config)
|
48
|
+
class Initializer
|
49
|
+
|
50
|
+
def initialize(configuration)
|
51
|
+
IronNails.configuration = configuration
|
52
|
+
|
53
|
+
initialize_logger
|
54
|
+
|
55
|
+
set_constants
|
56
|
+
require_binaries
|
57
|
+
include_namespaces
|
58
|
+
require_application_files
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.run(configuration = Configuration.new)
|
62
|
+
yield configuration if block_given?
|
63
|
+
initializer = new configuration
|
64
|
+
initializer
|
65
|
+
end
|
66
|
+
|
67
|
+
def configuration
|
68
|
+
IronNails.configuration
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_constants
|
72
|
+
logger.debug "setting application constants", IRONNAILS_FRAMEWORKNAME
|
73
|
+
end
|
74
|
+
|
75
|
+
# If the IRONNAILS_DEFAULT_LOGGER constant is already set, this initialization
|
76
|
+
# routine does nothing. If the constant is not set, and Configuration#logger
|
77
|
+
# is not +nil+, this also does nothing. Otherwise, a new logger instance
|
78
|
+
# is created at Configuration#log_path, with a default log level of
|
79
|
+
# Configuration#log_level.
|
80
|
+
#
|
81
|
+
# If the log could not be created, the log will be set to output to
|
82
|
+
# +STDERR+, with a log level of +WARN+.
|
83
|
+
def initialize_logger
|
84
|
+
# if the environment has explicitly defined a logger, use it
|
85
|
+
return if defined?(IRONNAILS_DEFAULT_LOGGER)
|
86
|
+
|
87
|
+
unless logr = configuration.logger
|
88
|
+
begin
|
89
|
+
logr = IronNails::Logging::BufferedLogger.new(configuration.log_path)
|
90
|
+
logr.level = IronNails::Logging::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
|
91
|
+
if configuration.environment == "production"
|
92
|
+
logr.auto_flushing = false
|
93
|
+
logr.set_non_blocking_io
|
94
|
+
end
|
95
|
+
rescue StandardError => e
|
96
|
+
logr = IronNails::Logging::BufferedLogger.new(STDERR)
|
97
|
+
logr.level = IronNails::Logging::BufferedLogger::WARN
|
98
|
+
logr.warn(
|
99
|
+
"IronNails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
|
100
|
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed. #{e}"
|
101
|
+
)
|
102
|
+
end
|
103
|
+
logr.debug "initializing logger", IRONNAILS_FRAMEWORKNAME
|
104
|
+
end
|
105
|
+
|
106
|
+
silence_warnings { Object.const_set "IRONNAILS_DEFAULT_LOGGER", logr }
|
107
|
+
end
|
108
|
+
|
109
|
+
def logger
|
110
|
+
IRONNAILS_DEFAULT_LOGGER
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def require_binaries
|
115
|
+
logger.debug "requiring binaries from bin", IRONNAILS_FRAMEWORKNAME
|
116
|
+
configuration.assembly_paths.each do |path|
|
117
|
+
require_files path, :dll
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def include_namespaces
|
123
|
+
logger.debug "Including namespaces", IRONNAILS_FRAMEWORKNAME
|
124
|
+
#include_global_namespaces configuration.namespaces
|
125
|
+
configuration.namespaces.each { |namespace| Object.send :include, eval(namespace) }
|
126
|
+
end
|
127
|
+
|
128
|
+
def require_application_files
|
129
|
+
logger.debug "requiring application files", IRONNAILS_FRAMEWORKNAME
|
130
|
+
configuration.application_paths.each do |path|
|
131
|
+
require_files path, :rb
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def require_files(path, extension)
|
136
|
+
Dir.glob("#{File.expand_path(path)}/*.#{extension}").each do |file|
|
137
|
+
# puts "#{file}"
|
138
|
+
require "#{file}" unless configuration.excluded_file? file
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/view_operations'
|
2
|
+
module IronNails
|
3
|
+
|
4
|
+
module Controller
|
5
|
+
|
6
|
+
class Base
|
7
|
+
|
8
|
+
include IronNails::Controller::ViewOperations
|
9
|
+
include IronNails::Logging::ClassLogger
|
10
|
+
include IronNails::Core::Observable
|
11
|
+
|
12
|
+
|
13
|
+
# Gets or sets the objects for the presenter
|
14
|
+
attr_accessor :objects
|
15
|
+
|
16
|
+
# Gets or sets the meta data for binding ui stuff we can't with Xaml (like Password on the PasswordBox)
|
17
|
+
attr_accessor :view_properties
|
18
|
+
|
19
|
+
# Gets or sets the commands for the presenter
|
20
|
+
attr_accessor :commands
|
21
|
+
|
22
|
+
# Gets or sets the presenters collection for this controller
|
23
|
+
attr_accessor :presenters
|
24
|
+
|
25
|
+
def controller_name
|
26
|
+
self.class.to_s.underscore.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_view
|
30
|
+
#log_on_error do
|
31
|
+
setup_for_showing_view
|
32
|
+
main_presenter.show_view
|
33
|
+
#end
|
34
|
+
end
|
35
|
+
|
36
|
+
def refresh_view(name=nil)
|
37
|
+
name ||= view_name.to_sym
|
38
|
+
setup_for_showing_view
|
39
|
+
nails_engine.refresh_view(nails_engine.find_view(controller_name, name))
|
40
|
+
on_view(name) do |proxy|
|
41
|
+
proxy.refresh
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def on_view(name=nil, options={}, &b)
|
46
|
+
name ||= view_name.to_sym
|
47
|
+
if block_given?
|
48
|
+
setup_for_showing_view
|
49
|
+
nails_engine.on_view(controller_name, name, &b)
|
50
|
+
else
|
51
|
+
if options[:set].nil?
|
52
|
+
nails_engine.from_view(controller_name, name, options[:from], options[:get])
|
53
|
+
else
|
54
|
+
nails_engine.set_on_view(controller_name, name, options[:from], options[:set], options[:value])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# def from_view(name, options)
|
60
|
+
# name ||= view_name.to_sym
|
61
|
+
# nails_engine.from_view(controller_name, name, options[:from], options[:get])
|
62
|
+
# end
|
63
|
+
|
64
|
+
def child_view(view_name, options)
|
65
|
+
nails_engine.register_child_view :controller => controller_name, :container => options[:in], :name => view_name
|
66
|
+
end
|
67
|
+
|
68
|
+
def view_model(model_name, value)
|
69
|
+
instance_variable_set "@#{model_name}", value
|
70
|
+
refresh_objects
|
71
|
+
nails_engine.set_viewmodel_for self, model_name, value
|
72
|
+
end
|
73
|
+
|
74
|
+
def configure_viewmodel_for_showing
|
75
|
+
nails_engine.configure_view_for_showing
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_update_ui_after(options, &b)
|
79
|
+
nails_engine.to_update_ui_after self, options, &b
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_ui_thread(options=nil, &b)
|
83
|
+
nails_engine.on_ui_thread self, options, &b
|
84
|
+
end
|
85
|
+
|
86
|
+
def play_storyboard(name=nil, storyboard=nil)
|
87
|
+
nails_engine.play_storyboard self, (storyboard.nil? ? view_name : name), (storyboard.nil? ? name : storyboard)
|
88
|
+
end
|
89
|
+
|
90
|
+
def stop_storyboard(name=nil, storyboard=nil)
|
91
|
+
nails_engine.stop_storyboard self, (storyboard.nil? ? view_name : name), (storyboard.nil? ? name : storyboard)
|
92
|
+
end
|
93
|
+
|
94
|
+
def init_controller
|
95
|
+
end
|
96
|
+
|
97
|
+
def __init_controller__
|
98
|
+
@command_builder = CommandBuilder.new self
|
99
|
+
init_controller
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
class << self
|
104
|
+
|
105
|
+
alias_method :old_nails_controller_new, :new
|
106
|
+
|
107
|
+
def new
|
108
|
+
ctrlr = old_nails_controller_new
|
109
|
+
ctrlr.__init_controller__
|
110
|
+
ctrlr
|
111
|
+
end
|
112
|
+
|
113
|
+
def view_action(name, options={}, &b)
|
114
|
+
@commands ||= {}
|
115
|
+
options[:action] = b if block_given?
|
116
|
+
@commands[name] = options
|
117
|
+
end
|
118
|
+
|
119
|
+
def view_object(name, options = nil)
|
120
|
+
@objects ||= {}
|
121
|
+
@view_properties ||={}
|
122
|
+
unless options.is_a?(Hash) && !options[:element].nil?
|
123
|
+
@objects[name] = options.is_a?(Hash) ? options[:value] : options
|
124
|
+
else
|
125
|
+
@view_properties[name] = options
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module IronNails
|
2
|
+
|
3
|
+
module Controller
|
4
|
+
|
5
|
+
# Encapsulates all the operations that have to do with the
|
6
|
+
# view model in controllers.
|
7
|
+
module ViewOperations
|
8
|
+
|
9
|
+
attr_accessor :nails_engine
|
10
|
+
|
11
|
+
# gets the view name for the class that includes this module
|
12
|
+
def view_name
|
13
|
+
self.class.demodulize.underscore.gsub(/_controller$/, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
# gets the name of the view model class
|
17
|
+
def view_model_name
|
18
|
+
"#{view_name}_view_model"
|
19
|
+
end
|
20
|
+
|
21
|
+
def nails_engine=(value)
|
22
|
+
@nails_engine = value
|
23
|
+
init_view_manager
|
24
|
+
end
|
25
|
+
|
26
|
+
# initializes a new instance of the ViewManager
|
27
|
+
def init_view_manager
|
28
|
+
|
29
|
+
nails_engine.add_observer :refreshing_view, controller_name do
|
30
|
+
setup_for_showing_view
|
31
|
+
end
|
32
|
+
copy_vars
|
33
|
+
#end
|
34
|
+
end
|
35
|
+
|
36
|
+
def synchronise_with_view_model
|
37
|
+
nails_engine.synchronise_to_controller self
|
38
|
+
refresh_instance_variables
|
39
|
+
end
|
40
|
+
|
41
|
+
# setup the viewmodel for the current objects and command defintions
|
42
|
+
def setup_for_showing_view
|
43
|
+
#log_on_error do
|
44
|
+
objs = ModelCollection.generate_for refresh_objects
|
45
|
+
cmds = @command_builder.generate_for commands
|
46
|
+
cmds.each do |cmd|
|
47
|
+
cmd.add_observer(:reading_input) do
|
48
|
+
synchronise_with_view_model
|
49
|
+
end
|
50
|
+
end
|
51
|
+
nails_engine.initialize_with cmds, objs
|
52
|
+
logger.debug "initialized the view manager", IRONNAILS_FRAMEWORKNAME
|
53
|
+
#end
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_action(name, options, &b)
|
57
|
+
options[:action] = b if block_given?
|
58
|
+
cmd_def = { "#{name}".to_sym => options }
|
59
|
+
nails_engine.add_command_to_view cmd_def
|
60
|
+
end
|
61
|
+
|
62
|
+
def refresh_objects
|
63
|
+
instance_variables.each do |var|
|
64
|
+
sym = var.gsub(/@/, "").to_sym
|
65
|
+
if objects.has_key?(sym)
|
66
|
+
val = instance_variable_get(var)
|
67
|
+
objects[sym] = val
|
68
|
+
end
|
69
|
+
end
|
70
|
+
objects
|
71
|
+
end
|
72
|
+
|
73
|
+
def refresh_instance_variables
|
74
|
+
objects.each do |k, v|
|
75
|
+
instance_variable_set "@#{k}", v
|
76
|
+
end
|
77
|
+
view_properties.each do |k, v|
|
78
|
+
val = on_view v[:view], :from => v[:element], :get => v[:property]
|
79
|
+
instance_variable_set "@#{k}", val
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# copies an instance variable from the class object to this instance
|
84
|
+
def instance_variable_copy(var)
|
85
|
+
log_on_error do
|
86
|
+
val = self.class.instance_variable_get var
|
87
|
+
instance_variable_set var, val
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# copies the instance variables from the class object to this instance
|
92
|
+
def copy_vars
|
93
|
+
self.class.instance_variables.each { |var| instance_variable_copy var }
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
# Extracts options from a set of arguments. Removes and returns the last
|
4
|
+
# element in the array if it's a hash, otherwise returns a blank hash.
|
5
|
+
#
|
6
|
+
# def options(*args)
|
7
|
+
# args.extract_options!
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# options(1, 2) # => {}
|
11
|
+
# options(1, 2, :a => :b) # => {:a=>:b}
|
12
|
+
def extract_options!
|
13
|
+
last.is_a?(::Hash) ? pop : {}
|
14
|
+
end
|
15
|
+
end
|