rapid-core 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +11 -0
  4. data/Gemfile.lock +53 -0
  5. data/Rakefile +61 -0
  6. data/cucumber.yml +3 -0
  7. data/doc/plan.txt +89 -0
  8. data/doc/scaffold/controller.rb +83 -0
  9. data/doc/scaffold/helper.rb +2 -0
  10. data/doc/scaffold/model.rb +5 -0
  11. data/doc/scaffold/rapid_scaffold.rb +5 -0
  12. data/doc/scaffold/views/_form.html.erb +25 -0
  13. data/doc/scaffold/views/edit.html.erb +6 -0
  14. data/doc/scaffold/views/index.html.erb +25 -0
  15. data/doc/scaffold/views/new.html.erb +5 -0
  16. data/doc/scaffold/views/show.html.erb +15 -0
  17. data/features/settings/boolean/default.feature +36 -0
  18. data/features/settings/double-nested/default.feature +50 -0
  19. data/features/settings/double-nested/if.feature +41 -0
  20. data/features/settings/double-nested/unless.feature +39 -0
  21. data/features/settings/double-nested/validates/exclusion_of.feature +30 -0
  22. data/features/settings/double-nested/validates/format_of.feature +30 -0
  23. data/features/settings/double-nested/validates/inclusion_of.feature +30 -0
  24. data/features/settings/double-nested/validates/length_of.feature +30 -0
  25. data/features/settings/double-nested/validates/presence_of.feature +37 -0
  26. data/features/settings/double-nested/validates/size_of.feature +30 -0
  27. data/features/settings/integer/default.feature +49 -0
  28. data/features/settings/nested/default.feature +50 -0
  29. data/features/settings/nested/if.feature +53 -0
  30. data/features/settings/nested/unless.feature +32 -0
  31. data/features/settings/nested/validates/exclusion_of.feature +30 -0
  32. data/features/settings/nested/validates/format_of.feature +30 -0
  33. data/features/settings/nested/validates/inclusion_of.feature +30 -0
  34. data/features/settings/nested/validates/length_of.feature +30 -0
  35. data/features/settings/nested/validates/presence_of.feature +37 -0
  36. data/features/settings/nested/validates/size_of.feature +30 -0
  37. data/features/settings/not_found.feature +33 -0
  38. data/features/settings/string/default.feature +36 -0
  39. data/features/settings/string/validates/exclusion_of.feature +30 -0
  40. data/features/settings/string/validates/format_of.feature +30 -0
  41. data/features/settings/string/validates/inclusion_of.feature +30 -0
  42. data/features/settings/string/validates/length_of.feature +30 -0
  43. data/features/settings/string/validates/presence_of.feature +37 -0
  44. data/features/settings/string/validates/size_of.feature +30 -0
  45. data/features/step_definitions/settings_steps.rb +92 -0
  46. data/features/step_definitions/skeleton_steps.rb +68 -0
  47. data/features/step_definitions/template_steps.rb +39 -0
  48. data/features/support/env.rb +6 -0
  49. data/features/templates/comment_if.feature +55 -0
  50. data/features/templates/comment_unless.feature +56 -0
  51. data/features/templates/for/for.feature +51 -0
  52. data/features/templates/if/else.feature +60 -0
  53. data/features/templates/if/elsif.feature +82 -0
  54. data/features/templates/if/if.feature +55 -0
  55. data/features/templates/namespaces/exist.feature +54 -0
  56. data/features/templates/static.feature +37 -0
  57. data/features/templates/variables.feature +61 -0
  58. data/lib/rapid/check.rb +162 -0
  59. data/lib/rapid/core.rb +37 -0
  60. data/lib/rapid/error.rb +84 -0
  61. data/lib/rapid/module.rb +35 -0
  62. data/lib/rapid/railtie.rb +18 -0
  63. data/lib/rapid/setting/base.rb +35 -0
  64. data/lib/rapid/setting/boolean_setting.rb +17 -0
  65. data/lib/rapid/setting/class_hash.rb +34 -0
  66. data/lib/rapid/setting/comments.rb +25 -0
  67. data/lib/rapid/setting/definer.rb +151 -0
  68. data/lib/rapid/setting/instance_hash.rb +132 -0
  69. data/lib/rapid/setting/instance_root.rb +107 -0
  70. data/lib/rapid/setting/integer_setting.rb +24 -0
  71. data/lib/rapid/setting/namespace/base.rb +113 -0
  72. data/lib/rapid/setting/namespace/instance.rb +84 -0
  73. data/lib/rapid/setting/nested_validations.rb +86 -0
  74. data/lib/rapid/setting/string_setting.rb +13 -0
  75. data/lib/rapid/settings.rb +129 -0
  76. data/lib/rapid/skeleton/base.rb +164 -0
  77. data/lib/rapid/skeleton/helpers/directory.rb +53 -0
  78. data/lib/rapid/skeleton/helpers/gem.rb +133 -0
  79. data/lib/rapid/skeleton/helpers/migration.rb +46 -0
  80. data/lib/rapid/skeleton/helpers/route.rb +115 -0
  81. data/lib/rapid/skeleton/helpers/script.rb +33 -0
  82. data/lib/rapid/skeleton/helpers/template.rb +73 -0
  83. data/lib/rapid/skeleton/helpers/view.rb +35 -0
  84. data/lib/rapid/spec/template.rb +104 -0
  85. data/lib/rapid/spec.rb +1 -0
  86. data/lib/rapid/tasks.rb +29 -0
  87. data/lib/rapid/template/base.rb +49 -0
  88. data/lib/rapid/template/node/base.rb +43 -0
  89. data/lib/rapid/template/node/comment_node.rb +42 -0
  90. data/lib/rapid/template/node/if_node.rb +109 -0
  91. data/lib/rapid/template/node/root.rb +51 -0
  92. data/lib/rapid/template/node/static.rb +29 -0
  93. data/lib/rapid/template/node/variable.rb +86 -0
  94. data/lib/rapid/template/parser.rb +167 -0
  95. data/lib/rapid/template/pulling/base.rb +91 -0
  96. data/lib/rapid/template/pulling/explicit.rb +92 -0
  97. data/lib/rapid/template/pulling/forgiving.rb +58 -0
  98. data/lib/rapid/version.rb +3 -0
  99. data/lib/rapid.rb +37 -0
  100. data/rapid-core.gemspec +26 -0
  101. data/spec/rapid/check_spec.rb +119 -0
  102. data/spec/rapid/error_spec.rb +14 -0
  103. data/spec/rapid/module_spec.rb +28 -0
  104. data/spec/rapid/setting/base_spec.rb +17 -0
  105. data/spec/rapid/setting/definer_spec.rb +318 -0
  106. data/spec/rapid/setting/instance_root_spec.rb +161 -0
  107. data/spec/rapid/setting/namespace/base_spec.rb +93 -0
  108. data/spec/rapid/setting/namespace/instance_spec.rb +12 -0
  109. data/spec/rapid/setting/nested_validations_spec.rb +72 -0
  110. data/spec/rapid/settings_spec.rb +51 -0
  111. data/spec/rapid/skeleton/base_spec.rb +224 -0
  112. data/spec/rapid/skeleton/helpers/directory_spec.rb +104 -0
  113. data/spec/rapid/skeleton/helpers/gem_spec.rb +180 -0
  114. data/spec/rapid/skeleton/helpers/migration_spec.rb +23 -0
  115. data/spec/rapid/skeleton/helpers/route_spec.rb +120 -0
  116. data/spec/rapid/skeleton/helpers/script_spec.rb +57 -0
  117. data/spec/rapid/skeleton/helpers/template_spec.rb +142 -0
  118. data/spec/rapid/skeleton/helpers/view_spec.rb +54 -0
  119. data/spec/rapid/spec/template_spec.rb +168 -0
  120. data/spec/rapid/template/base_spec.rb +290 -0
  121. data/spec/rapid/template/node/base_spec.rb +9 -0
  122. data/spec/rapid/template/node/comment_node_spec.rb +46 -0
  123. data/spec/rapid/template/node/if_node_spec.rb +28 -0
  124. data/spec/rapid/template/node/root_spec.rb +9 -0
  125. data/spec/rapid/template/node/static_spec.rb +17 -0
  126. data/spec/rapid/template/node/variable_spec.rb +87 -0
  127. data/spec/rapid/template/parser_spec.rb +187 -0
  128. data/spec/rapid/template/pulling/base_spec.rb +81 -0
  129. data/spec/rapid/template/pulling/explicit_spec.rb +33 -0
  130. data/spec/rapid/template/pulling/forgiving_spec.rb +132 -0
  131. data/spec/spec_helper.rb +10 -0
  132. metadata +325 -0
@@ -0,0 +1,164 @@
1
+ module Rapid
2
+ module Skeleton
3
+
4
+ class Base
5
+
6
+ include ActiveModel::Validations
7
+
8
+ include Skeleton::Helpers::Directory
9
+ include Skeleton::Helpers::Gem
10
+ include Skeleton::Helpers::Migration
11
+ include Skeleton::Helpers::Route
12
+ include Skeleton::Helpers::Script
13
+ include Skeleton::Helpers::Template
14
+ include Skeleton::Helpers::View
15
+
16
+ attr_reader :name, :settings, :project_path, :templates_path
17
+
18
+ delegate :get_binding, :to => :settings
19
+ delegate :load_yaml, :to => :settings
20
+ delegate :load_hash, :to => :settings
21
+ delegate :to_yaml, :to => :settings
22
+ delegate :to_hash, :to => :settings
23
+ delegate :to_dot_hash, :to => :settings
24
+ delegate :[], :to => :settings
25
+ delegate :[]=, :to => :settings
26
+ delegate :set?, :to => :settings
27
+
28
+ validate :validate_settings
29
+
30
+ def initialize settings = nil, options = {}
31
+ @settings = settings
32
+ @project_path = options[:project_path] || File.expand_path('.')
33
+ @templates_path = options[:templates_path] || discover_templates_path(options[:file])
34
+ @name = options[:name] || implied_name
35
+ end
36
+
37
+ def settings= hash
38
+ settings.load_hash hash
39
+ end
40
+
41
+ def push!
42
+ if push
43
+ true
44
+ else
45
+ raise Rapid::InvalidSkeletonError.new(errors.full_messages.join(', '))
46
+ end
47
+
48
+ true
49
+ end
50
+
51
+ def push
52
+ @pushing = true
53
+ is_valid = valid?
54
+ section(name) { bones } if is_valid
55
+ is_valid
56
+ ensure
57
+ @pushing = false
58
+ end
59
+
60
+ def pull!
61
+ if pull
62
+ true
63
+ else
64
+ raise Rapid::InvalidSkeletonError.new(self.class.name)
65
+ end
66
+ end
67
+
68
+ def pull
69
+ @pulling = true
70
+ !Rapid::Check.encounters_error? { section(name) { bones } }
71
+ ensure
72
+ @pulling = false
73
+ end
74
+
75
+ protected
76
+
77
+ def bones
78
+ raise NotImplementedError.new("subclass should implement bones")
79
+ end
80
+
81
+ def section name, options = {}, &block
82
+ if Rapid::Check.current
83
+ Rapid::Check.current.with_section name do
84
+ run_section name, options, &block
85
+ end
86
+ else
87
+ run_section name, options, &block
88
+ end
89
+ end
90
+
91
+ def pushing?
92
+ @pushing == true
93
+ end
94
+
95
+ def pulling?
96
+ @pulling == true
97
+ end
98
+
99
+ def ok file, message
100
+ log :ok, file, message
101
+ end
102
+
103
+ def warning file, message
104
+ log :warning, file, message
105
+ end
106
+
107
+ def error file, message
108
+ log :error, file, message
109
+ end
110
+
111
+ def exception file, exception
112
+ log :exception, file, exception
113
+ end
114
+
115
+ private
116
+
117
+ def run_section name, options
118
+ if Kernel.block_given?
119
+ yield
120
+ else
121
+ method_name = options[:method] || name
122
+ send method_name
123
+ end
124
+ end
125
+
126
+ def log type, file, message_or_exception
127
+ if Rapid::Check.current
128
+ Rapid::Check.current.send type, file, message_or_exception
129
+ else
130
+ raise "Rapid::Check.current is not set"
131
+ end
132
+
133
+ end
134
+
135
+ def validate_settings
136
+ if settings != nil && !settings.valid?
137
+ settings.errors.each do |attribute, errors|
138
+ errors.each {|error| self.errors.add attribute, error }
139
+ end
140
+ end
141
+
142
+ true
143
+ end
144
+
145
+ def discover_templates_path file_path
146
+ if file_path =~ /\/lib\//
147
+ path = File.join $`, 'templates'
148
+ return path if File.directory? path
149
+ end
150
+ end
151
+
152
+ def implied_name
153
+ name = self.class.name
154
+ if name =~ /::Skeleton$/
155
+ $`
156
+ else
157
+ name
158
+ end
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,53 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Directory
6
+
7
+ protected
8
+
9
+ def directory path, options = {}
10
+ if pushing?
11
+ push_directory path, options
12
+ elsif pulling?
13
+ pull_directory path, options
14
+ end
15
+ end
16
+
17
+ def push_directory path, options = {}
18
+ full_path = File.join project_path, path
19
+
20
+ if_setting = options[:if]
21
+ return if if_setting && !set?(if_setting)
22
+
23
+ FileUtils.mkdir_p full_path
24
+ end
25
+
26
+ def pull_directory path, options = {}
27
+ full_path = File.join project_path, path
28
+
29
+ if_setting = options[:if]
30
+
31
+ if !File.exists?(full_path)
32
+
33
+ if if_setting
34
+ self[if_setting] = false
35
+ ok path, "doesn't exist"
36
+ else
37
+ warning path, "doesn't exist"
38
+ end
39
+
40
+ elsif !File.directory?(full_path)
41
+ error path, "isn't a directory"
42
+
43
+ else
44
+ self[if_setting] = true if if_setting
45
+ ok path, "is good"
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,133 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Gem
6
+
7
+ def gemfile_path
8
+ File.join project_path, "Gemfile" if project_path
9
+ end
10
+
11
+ protected
12
+
13
+ def validate_gemfile_exists
14
+ path = gemfile_path
15
+ if path && !File.exists?(path)
16
+ errors.add :gem, "file does not exist"
17
+ end
18
+
19
+ true
20
+ end
21
+
22
+ def gem name, *args
23
+ if pushing?
24
+ push_gem name, *args
25
+ elsif pulling?
26
+ pull_gem name, *args
27
+ end
28
+ end
29
+
30
+ def pull_gem gem_name, *args
31
+ options = Hash === args.last ? args.pop : {}
32
+ version = args.first
33
+
34
+ path = gemfile_path
35
+
36
+ if path.blank?
37
+ error gem_name, "Unknown Gemfile location"
38
+ return
39
+ end
40
+
41
+ unless File.exists? path
42
+ error gem_name, "Gemfile doesn't exist"
43
+ return
44
+ end
45
+
46
+ content = File.open(path) {|f| f.read }
47
+
48
+ if_setting = options[:if]
49
+
50
+ if has_gem? gem_name, content
51
+ ok gem_name, "is in your Gemfile"
52
+ self[if_setting] = true if if_setting
53
+
54
+ elsif if_setting
55
+ ok gem_name, "isn't in your Gemfile"
56
+ self[if_setting] = false
57
+
58
+ else
59
+ error gem_name, "isn't in your Gemfile"
60
+ end
61
+ end
62
+
63
+ def push_gem name, *args
64
+ options = Hash === args.last ? args.pop : {}
65
+ version = args.first
66
+
67
+ path = gemfile_path
68
+ return false unless path
69
+
70
+ content = File.open(path) {|f| f.read }
71
+
72
+ add_gem_to_content! [name, version, options], content
73
+
74
+ File.open(path, 'w') {|f| f.write content }
75
+ true
76
+ end
77
+
78
+ def add_gem_to_content! gem, content
79
+ gem_name = gem.first
80
+ gem_version = gem[1]
81
+ gem_options = gem[2]
82
+
83
+ if_setting = gem_options.delete :if
84
+ return if if_setting && !set?(if_setting)
85
+
86
+ return if has_gem? gem, content
87
+
88
+ if gem_options[:group]
89
+ gem_group = gem_options[:group]
90
+ group_index = content.index %(group :#{gem_group} do)
91
+
92
+ elsif gem_options[:groups]
93
+ groups = gem_options[:groups]
94
+ group_index = content.index %(group #{groups.collect {|g| g.to_sym.inspect}.join(", ")} do)
95
+ end
96
+
97
+ if group_index
98
+ end_index = content.index("\nend", group_index)
99
+ rest = content[end_index+4..-1]
100
+
101
+ gem_options.delete :group
102
+ gem_options.delete :groups
103
+ gem_method = gem_method_call gem_name, gem_version, gem_options
104
+
105
+ content.sub! "\nend#{rest}", "\n #{gem_method}\nend#{rest}"
106
+ else
107
+ gem_method = gem_method_call gem_name, gem_version, gem_options
108
+ content << "\n#{gem_method}"
109
+ end
110
+ end
111
+
112
+ def has_gem? gem_name, content
113
+ content.index(%(gem "#{gem_name}")) != nil || content.index(%(gem '#{gem_name}')) != nil
114
+ end
115
+
116
+ def gem_method_call gem_name, gem_version, gem_options
117
+ gem_options[:group] = gem_options[:group].to_sym if gem_options.key? :group
118
+ groups = gem_options.delete :groups
119
+
120
+ gem_method = %(gem '#{gem_name}')
121
+ gem_method << ", '#{gem_version}'" unless gem_version.blank?
122
+ gem_method << ", #{gem_options.inspect[1..-2]}" unless gem_options.empty?
123
+ gem_method.gsub! "=>", " => "
124
+
125
+ gem_method << ", :groups => #{groups.collect {|g| g.to_sym}.inspect}" if groups
126
+ gem_method
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,46 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Migration
6
+
7
+ protected
8
+
9
+ # def migration migration_path
10
+ # if pushing?
11
+ # push_migration path
12
+ # elsif pulling?
13
+ # pull_migration path
14
+ # end
15
+ # end
16
+ #
17
+ # def push_migration migration_path
18
+ #
19
+ # end
20
+ #
21
+ # def unique_prefix
22
+ # if @timestamp
23
+ # @timestamp + 1
24
+ # else
25
+ # @timestamp ||= Time.now.strftime("%Y%m%d%H%M%S").to_i
26
+ # end
27
+ # end
28
+ #
29
+ # def create_migration migration
30
+ # if migration =~ /^[0-9]+_/
31
+ # suffix = $'
32
+ # else
33
+ # suffix = migration
34
+ # end
35
+ #
36
+ # template_path = File.join 'db', 'migrate', "#{migration}.rb"
37
+ # output_path = File.join 'db', 'migrate', "#{unique_prefix}_#{suffix}.rb"
38
+ #
39
+ # push_template template_path, :to => output_path
40
+ # end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,115 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Route
6
+
7
+ def routes_path
8
+ File.join project_path, "config", "routes.rb" if project_path
9
+ end
10
+
11
+ protected
12
+
13
+ def validate_routes_file_exists
14
+ path = routes_path
15
+ if path && !File.exists?(path)
16
+ errors.add :routes, "file does not exist"
17
+ end
18
+
19
+ true
20
+ end
21
+
22
+ def route type, path, options = {}
23
+ if pushing?
24
+ push_route type, path, options
25
+ elsif pulling?
26
+ pull_route type, path, options
27
+ end
28
+ end
29
+
30
+ def pull_route type, path, options = {}
31
+ file_path = routes_path
32
+
33
+ if file_path.blank?
34
+ error "config/routes.rb", "location is unknown"
35
+ return
36
+ end
37
+
38
+ unless File.exists? file_path
39
+ error "config/routes.rb", "doesn't exist"
40
+ return
41
+ end
42
+
43
+ content = File.open(file_path) {|f| f.read }
44
+
45
+ if has_route? content, type, path
46
+ ok "#{type} '#{path}'", "exists"
47
+ else
48
+ error "#{type} '#{path}'", "doesn't exist"
49
+ end
50
+ end
51
+
52
+ def push_route type, path, options = {}
53
+ file_path = routes_path
54
+ return false unless file_path
55
+
56
+ content = File.open(file_path) {|f| f.read }
57
+
58
+ add_route_to_content! content, type, path, options
59
+
60
+ File.open(file_path, 'w') {|f| f.write content }
61
+ true
62
+ end
63
+
64
+ def add_route_to_content! content, route_type, route_path, route_options
65
+ if route_options[:namespace]
66
+ add_route_to_namespace! content, route_type, route_path, route_options
67
+
68
+ elsif !has_route?(content, route_type, route_path)
69
+ route_method = route_method_call route_type, route_path, route_options
70
+ content.sub! /\nend$/, "\n #{route_method}\nend"
71
+ end
72
+ end
73
+
74
+ def add_route_to_namespace! content, route_type, route_path, route_options
75
+ namespace = route_options.delete :namespace
76
+ route_method = route_method_call route_type, route_path, route_options
77
+
78
+ namespace_index = content.index "\n namespace :#{namespace} do"
79
+ if namespace_index
80
+ # append to existing
81
+
82
+ end_index = content.index "\n end", namespace_index
83
+ rest = content[end_index+6..-1]
84
+
85
+ content.sub! "\n end#{rest}", "\n #{route_method}\n end#{rest}"
86
+
87
+ else
88
+ # append new to content
89
+
90
+ namespace_method = "namespace :#{namespace} do\n #{route_method}\n end"
91
+ content.sub! /\nend$/, "\n #{namespace_method}\nend"
92
+ end
93
+ end
94
+
95
+ def has_route? content, route_type, route_path
96
+ content.index(%(\n #{route_type} '#{route_path}')) != nil
97
+ end
98
+
99
+ def route_method_call route_type, route_path, route_options
100
+ route_method = %(#{route_type} '#{route_path}')
101
+
102
+ to_option = route_options[:to]
103
+ route_method += ", :to => '#{to_option}'" if to_option
104
+
105
+ as_option = route_options[:as]
106
+ route_method += ", :as => :#{as_option}" if as_option
107
+
108
+ route_method
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,33 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Script
6
+
7
+ protected
8
+
9
+ def script script_path, options = {}
10
+ if pushing?
11
+ push_script script_path, options
12
+ elsif pulling?
13
+ pull_script script_path, options
14
+ end
15
+ end
16
+
17
+ def push_script script_path, options = {}
18
+ push_template script_path, options
19
+
20
+ output_path = options[:to] || script_path
21
+ full_output_path = File.join project_path, output_path
22
+ File.chmod 0755, full_output_path
23
+ end
24
+
25
+ def pull_script script_path, options = {}
26
+ pull_template script_path, options
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,73 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module Template
6
+
7
+ protected
8
+
9
+ def template template_path, options = {}
10
+ if pushing?
11
+ push_template template_path, options
12
+ elsif pulling?
13
+ pull_template template_path, options
14
+ end
15
+ end
16
+
17
+ def push_template template_path, options = {}
18
+ if_setting = options[:if]
19
+ return false if if_setting && !set?(if_setting)
20
+
21
+ full_template_path = File.join templates_path, template_path
22
+ template_content = File.open(full_template_path) { |f| f.read }
23
+ template = Rapid::Template::Base.new template_content, :filename => template_path
24
+
25
+ output_path = options[:to] || template_path
26
+ full_output_path = File.join project_path, output_path
27
+
28
+ output_content = template.push self
29
+ FileUtils.mkdir_p File.dirname(full_output_path)
30
+ File.open(full_output_path, 'w') { |f| f.write output_content }
31
+
32
+ true
33
+
34
+ rescue Errno::ENOENT => e
35
+ raise Rapid::TemplateNotFoundError.new(e.message)
36
+ end
37
+
38
+ def pull_template template_path, options = {}
39
+ if_setting = options[:if]
40
+
41
+ full_template_path = File.join templates_path, template_path
42
+ template_content = File.open(full_template_path) { |f| f.read }
43
+ template = Rapid::Template::Base.new template_content, :filename => template_path
44
+
45
+ output_path = options[:to] || template_path
46
+ full_output_path = File.join project_path, output_path
47
+
48
+ unless File.exists? full_output_path
49
+ if if_setting
50
+ self[if_setting] = false
51
+ else
52
+ error output_path, "doesn't exist"
53
+ end
54
+ return
55
+ end
56
+
57
+ output_content = File.open(full_output_path) { |f| f.read }
58
+ begin
59
+ template.pull output_content
60
+ rescue Rapid::NotMatchingTemplateError => e
61
+ exception output_path, e
62
+ return
63
+ end
64
+
65
+ self[if_setting] = true if if_setting
66
+ ok output_path, "is good"
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,35 @@
1
+ module Rapid
2
+ module Skeleton
3
+ module Helpers
4
+
5
+ module View
6
+
7
+ protected
8
+
9
+ def view view_path
10
+ if pushing?
11
+ push_view view_path
12
+ elsif pulling?
13
+ pull_view view_path
14
+ end
15
+ end
16
+
17
+ def push_view view_path
18
+ template_path = File.join 'app', 'views', view_path
19
+ rapid_view_path = File.join 'lib', 'rapid', 'views', view_path
20
+
21
+ push_template template_path, :to => rapid_view_path
22
+ end
23
+
24
+ def pull_view view_path
25
+ template_path = File.join 'app', 'views', view_path
26
+ rapid_view_path = File.join 'lib', 'rapid', 'views', view_path
27
+
28
+ pull_template template_path, :to => rapid_view_path
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end