rails_artifactor 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/DESIGN_NOTES.textile +33 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +71 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/lib/rails_artifactor/artifact/base.rb +59 -0
  10. data/lib/rails_artifactor/artifact/crud/create.rb +12 -0
  11. data/lib/rails_artifactor/artifact/crud/delete.rb +34 -0
  12. data/lib/rails_artifactor/artifact/crud/read.rb +47 -0
  13. data/lib/rails_artifactor/artifact/crud/update.rb +25 -0
  14. data/lib/rails_artifactor/artifact/crud.rb +32 -0
  15. data/lib/rails_artifactor/artifact/file_name/artifacts.rb +21 -0
  16. data/lib/rails_artifactor/artifact/file_name/migration.rb +54 -0
  17. data/lib/rails_artifactor/artifact/file_name/view.rb +172 -0
  18. data/lib/rails_artifactor/artifact/markers.rb +73 -0
  19. data/lib/rails_artifactor/artifact/migration.rb +11 -0
  20. data/lib/rails_artifactor/artifact/orm/active_record.rb +14 -0
  21. data/lib/rails_artifactor/artifact/orm/data_mapper.rb +22 -0
  22. data/lib/rails_artifactor/artifact/orm/mongo_mapper.rb +18 -0
  23. data/lib/rails_artifactor/artifact/orm/mongoid.rb +23 -0
  24. data/lib/rails_artifactor/artifact/orm/none.rb +16 -0
  25. data/lib/rails_artifactor/artifact/orm.rb +55 -0
  26. data/lib/rails_artifactor/artifact/view_artifact.rb +94 -0
  27. data/lib/rails_artifactor/artifact.rb +1 -0
  28. data/lib/rails_artifactor/base/crud/create.rb +62 -0
  29. data/lib/rails_artifactor/base/crud/delete.rb +35 -0
  30. data/lib/rails_artifactor/base/crud/read.rb +13 -0
  31. data/lib/rails_artifactor/base/crud/update.rb +66 -0
  32. data/lib/rails_artifactor/base/crud.rb +6 -0
  33. data/lib/rails_artifactor/base/file_name.rb +41 -0
  34. data/lib/rails_artifactor/base.rb +1 -0
  35. data/lib/rails_artifactor/macro.rb +2 -0
  36. data/lib/rails_artifactor/namespaces.rb +10 -0
  37. data/lib/rails_artifactor/rspec/configure.rb +7 -0
  38. data/lib/rails_artifactor/rspec.rb +1 -0
  39. data/lib/rails_artifactor/ruby_mutator.rb +11 -0
  40. data/lib/rails_artifactor/template_language/base.rb +14 -0
  41. data/lib/rails_artifactor/template_language/erb.rb +24 -0
  42. data/lib/rails_artifactor/template_language/haml.rb +32 -0
  43. data/lib/rails_artifactor/template_language/slim.rb +15 -0
  44. data/lib/rails_artifactor.rb +12 -0
  45. data/rails_artifactor.gemspec +163 -0
  46. data/spec/fixtures/app/views/account/edit.erb.html +3 -0
  47. data/spec/fixtures/app/views/account/edit.html.erb +3 -0
  48. data/spec/fixtures/app/views/layouts/application.erb.html +3 -0
  49. data/spec/fixtures/app/views/layouts/application.html.erb +16 -0
  50. data/spec/fixtures.rb +3 -0
  51. data/spec/rails_artifactor/artifact/base_spec.rb +17 -0
  52. data/spec/rails_artifactor/artifact/crud/controller_spec.rb +65 -0
  53. data/spec/rails_artifactor/artifact/crud/helper_spec.rb +64 -0
  54. data/spec/rails_artifactor/artifact/crud/mailer_spec.rb +62 -0
  55. data/spec/rails_artifactor/artifact/crud/migration_spec.rb +86 -0
  56. data/spec/rails_artifactor/artifact/crud/model_active_record_spec.rb +68 -0
  57. data/spec/rails_artifactor/artifact/crud/model_spec.rb +68 -0
  58. data/spec/rails_artifactor/artifact/crud/observer_spec.rb +65 -0
  59. data/spec/rails_artifactor/artifact/crud/permit_spec.rb +71 -0
  60. data/spec/rails_artifactor/artifact/crud/view_controller_action_spec.rb +92 -0
  61. data/spec/rails_artifactor/artifact/crud/view_file_spec.rb +31 -0
  62. data/spec/rails_artifactor/artifact/file_name/artifacts_spec.rb +33 -0
  63. data/spec/rails_artifactor/artifact/file_name/migration_spec.rb +32 -0
  64. data/spec/rails_artifactor/artifact/file_name/view_spec.rb +38 -0
  65. data/spec/rails_artifactor/artifact/markers_spec.rb +93 -0
  66. data/spec/rails_artifactor/artifact/migration_spec.rb +0 -0
  67. data/spec/rails_artifactor/artifact/orm/active_record_spec.rb +37 -0
  68. data/spec/rails_artifactor/artifact/orm/data_mapper_spec.rb +37 -0
  69. data/spec/rails_artifactor/artifact/orm/mongo_mapper_spec.rb +67 -0
  70. data/spec/rails_artifactor/artifact/orm/mongoid_spec.rb +67 -0
  71. data/spec/rails_artifactor/artifact/orm/none_spec.rb +36 -0
  72. data/spec/rails_artifactor/base/crud/create_spec.rb +31 -0
  73. data/spec/rails_artifactor/base/crud/delete_spec.rb +49 -0
  74. data/spec/rails_artifactor/base/crud/read_spec.rb +80 -0
  75. data/spec/rails_artifactor/base/crud/update_spec.rb +74 -0
  76. data/spec/rails_artifactor/base/file_name_spec.rb +23 -0
  77. data/spec/spec_helper.rb +9 -0
  78. metadata +234 -0
@@ -0,0 +1,73 @@
1
+ module RailsAssist::Artifact
2
+ module Marker
3
+ def marker name, type, options=nil
4
+ method = "#{type}_marker"
5
+ raise "No such marker method in this context: #{self}, ##{method}" if !respond_to? method
6
+ send method, name, options
7
+ end
8
+ end
9
+
10
+ module Controller
11
+ def controller_marker name, options=nil
12
+ "#{name.to_s.camelize}Controller < ActionController::Base"
13
+ end
14
+
15
+ extend self
16
+ end
17
+
18
+ module Helper
19
+ def helper_marker name, options=nil
20
+ "#{name.to_s.camelize}Helper"
21
+ end
22
+
23
+ extend self
24
+ end
25
+
26
+ module Permit
27
+ def permit_marker name, options=nil
28
+ "#{name.to_s.camelize}Permit < Permit::Base"
29
+ end
30
+
31
+ extend self
32
+ end
33
+
34
+ module Mailer
35
+ def mailer_marker name, options=nil
36
+ "#{name.to_s.camelize}Mailer < ActionMailer::Base"
37
+ end
38
+
39
+ extend self
40
+ end
41
+
42
+ module Observer
43
+ def observer_marker name, options=nil
44
+ "#{name.to_s.camelize}Observer < ActiveRecord::Observer"
45
+ end
46
+
47
+ extend self
48
+ end
49
+
50
+ module Migration
51
+ def migration_marker name, options=nil
52
+ "#{name.to_s.camelize} < ActiveRecord::Migration"
53
+ end
54
+
55
+ extend self
56
+ end
57
+
58
+ module Model
59
+ include RailsAssist::BaseHelper
60
+
61
+ def model_marker name, options={}
62
+ return send :orm_marker_name, name, options if respond_to?(:orm_marker_name)
63
+ name.to_s.camelize
64
+ end
65
+
66
+ def orm_notify
67
+ ". You must specify an ORM with the macro use_orm, f.ex -- use_orm :active_record"
68
+ end
69
+
70
+ extend self
71
+ end
72
+
73
+ end
@@ -0,0 +1,11 @@
1
+ require 'migration_assist'
2
+
3
+ RailsAssist::Migration.rails_root_dir = RailsAssist::Directory.rails_root
4
+
5
+ module RailsAssist::Artifact
6
+ module Migration
7
+ include RailsAssist::BaseHelper
8
+ include RailsAssist::Migration::ClassMethods
9
+ include RailsAssist::Artifact::FileName
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module RailsAssist::Orm
2
+ module ActiveRecord
3
+ include RailsAssist::Orm::Base
4
+
5
+ def orm_marker_name name, options=nil
6
+ 'ActiveRecord::Base'
7
+ end
8
+
9
+ def new_model_content name, options={}, &block
10
+ content = block ? yield : options[:content]
11
+ file_w_inherit(name, orm_marker_name(name, options)) { content }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module RailsAssist::Orm
2
+ module DataMapper
3
+ include RailsAssist::Orm::Base
4
+
5
+ def orm_name
6
+ 'DataMapper'
7
+ end
8
+
9
+ def orm_marker_name name, options=nil
10
+ "#{orm_name}::Resource"
11
+ end
12
+
13
+ def new_model_content name, options={}, &block
14
+ content = block ? yield : options[:content]
15
+ file_w_include(name, orm_marker_name(name, options)) { content }
16
+ end
17
+
18
+ def field_name
19
+ 'property'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module RailsAssist::Orm
2
+ module MongoMapper
3
+ include RailsAssist::Orm::Base
4
+
5
+ def orm_name
6
+ 'MongoMapper'
7
+ end
8
+
9
+ def new_model_content name, options={}, &block
10
+ content = block ? yield : options[:content]
11
+ file_w_include(name, orm_marker_name(name, options)) { content }
12
+ end
13
+
14
+ def field_name
15
+ 'key'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module RailsAssist::Orm
2
+ module Mongoid
3
+ include RailsAssist::Orm::Base
4
+
5
+ def orm_name
6
+ 'Mongoid'
7
+ end
8
+
9
+ def field_name
10
+ 'field'
11
+ end
12
+
13
+ def new_model_content name, options={}, &block
14
+ content = block ? yield : options[:content]
15
+ file_w_include(name, orm_marker_name(name, options)) { content }
16
+ end
17
+
18
+ def field name, type = nil
19
+ return "#{field_name} :#{name}, :type => #{type}" if type
20
+ "#{field_name} :#{name}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_support/inflector'
2
+
3
+ module RailsAssist::Orm
4
+ module None
5
+ include RailsAssist::Orm::Base
6
+
7
+ def orm_marker_name name, options=nil
8
+ name.to_s.camelize
9
+ end
10
+
11
+ def new_model_content name, options={}, &block
12
+ content = block ? yield : options[:content]
13
+ simple_file(name, orm_marker_name(name, options)) { content }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ module RailsAssist
2
+ module Orm
3
+ module Base
4
+ def self.included base
5
+ base.class_eval do
6
+ include RailsAssist::Artifact::Model
7
+ end
8
+ end
9
+
10
+ protected
11
+
12
+ def orm_marker_name name, options = {:model_type => :document}
13
+ document_name options
14
+ end
15
+
16
+ def document_name options = {:model_type => :document}
17
+ type_content = options[:model_type] == :embedded ? "#{orm_name}::EmbeddedDocument" : "#{orm_name}::Document"
18
+ end
19
+
20
+ def clazz name
21
+ "class #{name.to_s.camelize}"
22
+ end
23
+
24
+ def file name, include_stmt, &block
25
+ %Q{#{clazz name}
26
+ #{include_stmt}
27
+ #{yield if block}
28
+ end}
29
+ end
30
+
31
+ def file_w_include name, module_name, &block
32
+ file name, "include #{module_name}", &block
33
+ end
34
+
35
+ def simple_file name, module_name, &block
36
+ %Q{#{clazz name}
37
+ #{yield if block}
38
+ end}
39
+ end
40
+
41
+ def file_w_inherit name, module_name, &block
42
+ %Q{#{clazz name} < #{module_name}
43
+ #{yield if block}
44
+ end}
45
+ end
46
+
47
+ def field name, type = nil
48
+ return "#{field_name} :#{name}, #{type}" if type
49
+ "#{field_name} :#{name}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ require_all File.dirname(__FILE__) + '/orm'
@@ -0,0 +1,94 @@
1
+ module RailsAssist::Artifact
2
+ module View
3
+ include RailsAssist::BaseHelper
4
+ include RailsAssist::Artifact::CRUD
5
+
6
+ def has_view? name, *args, &block
7
+ file_name = view_file_name(name, args)
8
+ file_name.path.file?
9
+ end
10
+
11
+ def has_views? *args, &block
12
+ options = last_option args
13
+ args.to_strings.each do |name|
14
+ return false if !has_view? name, options
15
+ end
16
+ true
17
+ end
18
+
19
+ def view_file *args
20
+ view_file_name(args)
21
+ end
22
+
23
+ # CREATE
24
+ def create_view *args, &block
25
+ file_name = view_file_name(args)
26
+ dir = File.dirname(file_name)
27
+ FileUtils.mkdir_p dir if !File.directory?(dir)
28
+
29
+ content = get_view_content(args) || yield if block
30
+
31
+ # abort if no content given
32
+ debug "Warning: Content must be passed in either as a :content hash or a block" if !content
33
+ return nil if !content
34
+
35
+ debug "Writing view file: #{file_name}"
36
+ # write file content of view
37
+ File.open(file_name, 'w') do |f|
38
+ f.puts content
39
+ end
40
+ end
41
+
42
+ # READ
43
+ def read_view *args, &block
44
+ file_name = view_file_name(args)
45
+ debug "reading from: #{file_name}"
46
+ begin
47
+ file = File.new(file_name)
48
+ content = file.read
49
+ debug "read content: #{content}"
50
+ yield content if block
51
+ content
52
+ rescue
53
+ nil
54
+ end
55
+ end
56
+
57
+ # UPDATE
58
+ def insert_into_view *args, &block
59
+ begin
60
+ file_name = view_file_name(args)
61
+ debug "file insertion (view): #{file_name}"
62
+ options = last_option args
63
+ raise ArgumentError, ":before or :after option must be specified for insertion" if !(options[:before] || options[:after])
64
+ File.insert_into file_name, options, &block
65
+ true
66
+ rescue
67
+ nil
68
+ end
69
+ end
70
+
71
+ # DELETE
72
+ def remove_view *args
73
+ file = view_file_name(args)
74
+ FileUtils.rm_f(file) if File.exist?(file)
75
+ end
76
+
77
+ # remove_views :edit, :show, :folder => :person
78
+ def remove_views *args
79
+ options = last_option args
80
+ raise ArgumentError, "Missing :folder option in the last argument which must be a Hash" if !options && !options[:folder]
81
+ args.to_symbols.each{|name| remove_view name, options}
82
+ end
83
+
84
+ def get_view_content args
85
+ args = args.flatten
86
+ case args.first
87
+ when Hash
88
+ args.first[:content]
89
+ end
90
+ end
91
+
92
+ multi_aliases_for :view
93
+ end
94
+ end
@@ -0,0 +1 @@
1
+ require_all File.dirname(__FILE__) + '/artifact'
@@ -0,0 +1,62 @@
1
+ require 'rails_artifactor/ruby_mutator'
2
+
3
+ module RailsAssist::Artifact::CRUD
4
+ module Create
5
+ include RailsAssist::Artifact::Marker
6
+
7
+ def create_artifact name, options={}, &block
8
+ type = get_type(options)
9
+ file = make_file_name(name, type)
10
+ return nil if File.exist?(file) && options[:no_overwrite]
11
+
12
+ create_artifact_dir(file)
13
+ content = get_content(name, type, options, &block)
14
+
15
+ superclass = options[:superclass] if options[:superclass]
16
+
17
+ if superclass
18
+ content.extend(RailsAssist::RubyMutator)
19
+ content.remove_superclass
20
+ content.inherit_from "#{superclass}_permit"
21
+ end
22
+
23
+ return if content.blank?
24
+
25
+ File.overwrite file, content
26
+ end
27
+
28
+ protected
29
+
30
+ def new_artifact_content name, options = {}, &block
31
+ type = get_type(options)
32
+ content = extract_content type, options, &block
33
+ %Q{class #{marker(name, type)}
34
+ #{content}
35
+ end}
36
+ end
37
+
38
+ def create_artifact_dir file
39
+ # make dir
40
+ dir = File.dirname(file)
41
+ FileUtils.mkdir_p dir if !File.directory?(dir)
42
+ end
43
+
44
+ def content_method type
45
+ method = :"new_#{type}_content"
46
+ raise "Content method #{content_method} not found #{orm_notify}" if !respond_to?(method)
47
+ method
48
+ end
49
+
50
+ def extract_content type, options, &block
51
+ content = block ? yield : options[:content]
52
+ content = type == :model ? options.merge(:content => content) : content
53
+ end
54
+
55
+ def get_content name, type, options = {}, &block
56
+ content = extract_content type, options, &block
57
+ method = content_method(type)
58
+ options[:content] = content
59
+ send method, name, options, &block
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,35 @@
1
+ require 'sugar-high/array'
2
+
3
+ require 'rails_artifactor/artifact/file_name/view'
4
+
5
+ module RailsAssist::Artifact::CRUD
6
+ module Delete
7
+ class ViewHelper
8
+ extend RailsAssist::Artifact::View::FileName
9
+ end
10
+
11
+ def remove_artifact name, *args
12
+ file = ViewHelper.view_file_name(name, args)
13
+ return FileUtils.rm_f(file) if File.exist?(file)
14
+
15
+ type = args.first
16
+ type = type[:type] if type.kind_of? Hash
17
+ begin
18
+ file = existing_file_name name, type
19
+ FileUtils.rm_f(file)
20
+ debug "removed artifact: #{name}"
21
+ true
22
+ rescue
23
+ debug "artifact to remove not found: #{name}"
24
+ nil
25
+ end
26
+ end
27
+ alias_method :delete_artifact, :remove_artifact
28
+
29
+ def remove_artifacts *names
30
+ type = last_option(names)[:type]
31
+ names.flatten.select_labels.each{|name| remove_artifact(name, type) }
32
+ end
33
+ alias_method :delete_artifacts, :remove_artifacts
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ require 'sugar-high/file'
2
+
3
+ module RailsAssist::Artifact::CRUD
4
+ module Read
5
+ # TODO: Support :before and :after hash options!
6
+ def read_artifact(name, options = {}, &block)
7
+ type = get_type(options)
8
+ file_name = existing_file_name(name, type)
9
+ debug "reading from: #{file_name}"
10
+ File.read_from file_name, options, &block
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,66 @@
1
+ require 'sugar-high/arguments'
2
+
3
+ module RailsAssist::Artifact::CRUD
4
+ module Update
5
+ def insert_into_artifact name, options={}, &block
6
+ type = get_type(options)
7
+ file = existing_file_name(name, type)
8
+
9
+ raise "No file could be determined: #{file} from name: #{name} of type: #{type}" if !file
10
+ raise "File to insert in not found: #{file} for #{type}" if !File.file?(file)
11
+
12
+ marker = marker_option(name, options)
13
+
14
+ blip = send :"#{type}_marker", name, options
15
+ options1 = options.merge marker
16
+
17
+ before_last = options[:before_last]
18
+
19
+ res = File.insert_into file, options1, &block
20
+ if !res
21
+ # try with :embedded option if default doesn't work
22
+ mrk_opt = marker_option name, options.merge(:model_type => :embedded)
23
+ options.merge! mrk_opt
24
+
25
+ File.insert_into file, options, &block
26
+ end
27
+ end
28
+ alias_method :update_artifact, :insert_into_artifact
29
+
30
+ def remove_from_artifact name, options={}, &block
31
+ type = options[:type]
32
+ file = existing_file_name(name, type)
33
+ File.remove_content_from file, options, &block
34
+ end
35
+
36
+ def remove_from_artifacts *names, &block
37
+ options = last_option(names)
38
+ type = options[:type]
39
+ artifacts = names.flatten.select_labels
40
+
41
+ artifacts.each do |name|
42
+ file = existing_file_name(name, type)
43
+ File.remove_content_from file, options, &block
44
+ end
45
+ end
46
+ alias_hash :remove_from_artifact => :delete_from_artifact, :pluralize => true
47
+
48
+ def replace_in_artifact name, options={}, &block
49
+ type = options[:type]
50
+ file = existing_file_name(name, type)
51
+ File.replace_content_from file, options, &block
52
+ end
53
+
54
+ def replace_in_artifacts *names, &block
55
+ options = last_option(names)
56
+ type = options[:type]
57
+ artifacts = names.flatten.select_labels
58
+
59
+ artifacts.each do |name|
60
+ file = existing_file_name(name, type)
61
+ File.replace_content_from file, options, &block
62
+ end
63
+ end
64
+ alias_hash :replace_in_artifact => :update_artifact, :pluralize => true
65
+ end
66
+ end
@@ -0,0 +1,6 @@
1
+ require 'sugar-high/includes'
2
+ require_all File.dirname(__FILE__) + '/crud'
3
+
4
+ module RailsAssist::Artifact::CRUD
5
+ extends_and_includes :create, :read, :update, :delete
6
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails_assist/artifact'
2
+
3
+ module RailsAssist::Artifact
4
+ module FileName
5
+ include RailsAssist::Artifact::Directory
6
+ include RailsAssist::Artifact::Path
7
+
8
+ def make_file_name name, type, options={}
9
+ send :"#{type}_file_name", name, options
10
+ end
11
+
12
+ def existing_file_name name, type=nil, options = {}
13
+ # first try finder method
14
+ finder_method = :"find_#{type}"
15
+ if respond_to?(finder_method)
16
+ result = send finder_method, name, options
17
+ if !result.kind_of? String
18
+ raise IOError, "The call to #find_#{type}(#{name}) didn't find an existing #{type} file. Error in find expression: #{result.find_expr}"
19
+ end
20
+ return result
21
+ elsif type == :migration
22
+ raise StandardError, "The method #find_#{type} to find the migration is not available!"
23
+ end
24
+
25
+ # default for non-migration
26
+ file_name = make_file_name name, type, options
27
+ raise IOError, "No file for :#{type} found at location: #{file_name}" if !File.file?(file_name)
28
+ file_name
29
+ end
30
+
31
+ RailsAssist.artifacts.each do |name|
32
+ class_eval %{
33
+ def existing_#{name}_file name, type=nil, options = {}
34
+ existing_file_name name, type, options
35
+ end
36
+ }
37
+ end
38
+ end # file_name
39
+
40
+ include FileName
41
+ end
@@ -0,0 +1 @@
1
+ require_all File.dirname(__FILE__) + '/base'
@@ -0,0 +1,2 @@
1
+ # RailsAssist::UseMacro
2
+
@@ -0,0 +1,10 @@
1
+ require 'rails_assist'
2
+
3
+ module RailsAssist
4
+ module Artifact
5
+ modules :crud
6
+ modules RailsAssist.artifacts do
7
+ nested_modules :file_name
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec/core'
2
+ require 'rails_artifactor/macro'
3
+
4
+ RSpec.configure do |config|
5
+ config.extend RailsAssist::UseMacro
6
+ config.include RailsAssist::UseMacro
7
+ end
@@ -0,0 +1 @@
1
+ require_all File.dirname(__FILE__) + '/rspec'
@@ -0,0 +1,11 @@
1
+ module RailsAssist
2
+ module RubyMutator
3
+ def remove_superclass
4
+ self.gsub! /(class\s+\w+\s*)<\s*(\w|::)+/, '\1'
5
+ end
6
+
7
+ def inherit_from superclass
8
+ self.gsub! /(class\s+(\w|::)+)/, '\1' + " < #{superclass.to_s.camelize}\n"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module RailsAssist
2
+ module TemplateLanguage
3
+ class Base
4
+ def insert_ruby_statement statement, options = {}, &block
5
+ end
6
+
7
+ def insert_ruby_block statement, options = {}, &block
8
+ end
9
+
10
+ def insert_tag tag, css, options= {}, &block
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAssist
2
+ module TemplateLanguage
3
+ class Erb < Base
4
+ def insert_ruby_statement statement, options = {}
5
+ "<%= #{statement} %>"
6
+ end
7
+
8
+ def insert_ruby_block statement, options = {}, &block
9
+ %Q{"<%= #{statement} %>"
10
+ #{yield}
11
+ <% end %>
12
+ }
13
+ # insert_content options
14
+ end
15
+
16
+ def insert_tag tag, attributes, options= {}, &block
17
+ %Q{"<#{tag} #{attributes}>"
18
+ #{yield}
19
+ <#{tag}/>
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ module RailsAssist
2
+ module TemplateLanguage
3
+ class Haml < Base
4
+ def insert_ruby_statement statement, options = {}
5
+ "\n= #{statement}"
6
+ end
7
+
8
+ def insert_ruby_block statement, options = {}, &block
9
+ # get indentation of previous line
10
+ %Q{"<%= #{statement} %>"
11
+ #{yield}
12
+ <% end %>
13
+ }
14
+ end
15
+
16
+ def insert_tag tag, options= {}, &block
17
+ attributes = options[:attributes]
18
+ atr_atr = "{#{format attributes}}" if attributes
19
+ %Q{"%#{tag}#{atr_atr}"
20
+ #{yield}
21
+ <#{tag}/>
22
+ }
23
+ end
24
+
25
+ protected
26
+
27
+ def format attributes
28
+ attributes.map{|key, value| ":#{key} => \"#{value}\""}
29
+ end
30
+ end
31
+ end
32
+ end