rails_artifactor 0.5.0 → 0.5.1
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.
- data/VERSION +1 -1
- data/lib/rails_artifactor/artifact/asset_artifact.rb +120 -0
- data/lib/rails_artifactor/artifact/base.rb +9 -9
- data/lib/rails_artifactor/artifact/crud.rb +6 -6
- data/lib/rails_artifactor/artifact/crud/create.rb +2 -2
- data/lib/rails_artifactor/artifact/crud/delete.rb +13 -13
- data/lib/rails_artifactor/artifact/crud/update.rb +5 -5
- data/lib/rails_artifactor/artifact/file_name/artifacts.rb +4 -4
- data/lib/rails_artifactor/artifact/file_name/asset.rb +176 -0
- data/lib/rails_artifactor/artifact/file_name/view.rb +42 -42
- data/lib/rails_artifactor/artifact/markers.rb +24 -25
- data/lib/rails_artifactor/artifact/orm.rb +5 -5
- data/lib/rails_artifactor/artifact/orm/active_record.rb +2 -2
- data/lib/rails_artifactor/artifact/orm/data_mapper.rb +2 -2
- data/lib/rails_artifactor/artifact/orm/mongo_mapper.rb +4 -4
- data/lib/rails_artifactor/artifact/orm/mongoid.rb +2 -2
- data/lib/rails_artifactor/artifact/orm/none.rb +1 -1
- data/lib/rails_artifactor/artifact/view_artifact.rb +11 -11
- data/lib/rails_artifactor/base/crud/create.rb +14 -14
- data/lib/rails_artifactor/base/crud/delete.rb +10 -10
- data/lib/rails_artifactor/base/crud/update.rb +21 -21
- data/lib/rails_artifactor/base/file_name.rb +12 -12
- data/lib/rails_artifactor/template_language/base.rb +3 -3
- data/lib/rails_artifactor/template_language/erb.rb +4 -4
- data/lib/rails_artifactor/template_language/haml.rb +5 -6
- data/lib/rails_artifactor/template_language/slim.rb +5 -5
- data/rails_artifactor.gemspec +13 -10
- data/spec/rails_artifactor/artifact/crud/asset_spec.rb +56 -0
- data/spec/rails_artifactor/artifact/crud/view_controller_action_spec.rb +12 -12
- data/spec/rails_artifactor/artifact/crud/view_file_spec.rb +6 -6
- metadata +17 -14
@@ -7,20 +7,20 @@ module RailsAssist::Artifact::CRUD
|
|
7
7
|
class ViewHelper
|
8
8
|
extend RailsAssist::Artifact::View::FileName
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
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
|
12
|
+
file = ViewHelper.view_file_name(name, args)
|
13
|
+
return FileUtils.rm_f(file) if File.exist?(file)
|
14
|
+
|
15
|
+
type = args.first
|
16
16
|
type = type[:type] if type.kind_of? Hash
|
17
17
|
begin
|
18
18
|
file = existing_file_name name, type
|
19
|
-
FileUtils.rm_f(file)
|
20
|
-
debug "removed artifact: #{name}"
|
19
|
+
FileUtils.rm_f(file)
|
20
|
+
debug "removed artifact: #{name}"
|
21
21
|
true
|
22
22
|
rescue
|
23
|
-
debug "artifact to remove not found: #{name}"
|
23
|
+
debug "artifact to remove not found: #{name}"
|
24
24
|
nil
|
25
25
|
end
|
26
26
|
end
|
@@ -30,6 +30,6 @@ module RailsAssist::Artifact::CRUD
|
|
30
30
|
type = last_option(names)[:type]
|
31
31
|
names.flatten.select_labels.each{|name| remove_artifact(name, type) }
|
32
32
|
end
|
33
|
-
alias_method :delete_artifacts, :remove_artifacts
|
33
|
+
alias_method :delete_artifacts, :remove_artifacts
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
@@ -6,30 +6,30 @@ module RailsAssist::Artifact::CRUD
|
|
6
6
|
type = get_type(options)
|
7
7
|
file = existing_file_name(name, type)
|
8
8
|
|
9
|
-
raise "No file could be determined: #{file} from name: #{name} of type: #{type}" if !file
|
9
|
+
raise "No file could be determined: #{file} from name: #{name} of type: #{type}" if !file
|
10
10
|
raise "File to insert in not found: #{file} for #{type}" if !File.file?(file)
|
11
|
-
|
12
|
-
marker = marker_option(name, options)
|
13
|
-
|
11
|
+
|
12
|
+
marker = marker_option(name, options)
|
13
|
+
|
14
14
|
blip = send :"#{type}_marker", name, options
|
15
|
-
options1 = options.merge marker
|
15
|
+
options1 = options.merge marker
|
16
|
+
|
17
|
+
before_last = options[:before_last]
|
16
18
|
|
17
|
-
before_last = options[:before_last]
|
18
|
-
|
19
19
|
res = File.insert_into file, options1, &block
|
20
20
|
if !res
|
21
21
|
# try with :embedded option if default doesn't work
|
22
22
|
mrk_opt = marker_option name, options.merge(:model_type => :embedded)
|
23
23
|
options.merge! mrk_opt
|
24
24
|
|
25
|
-
File.insert_into file, options, &block
|
25
|
+
File.insert_into file, options, &block
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
28
28
|
alias_method :update_artifact, :insert_into_artifact
|
29
|
-
|
29
|
+
|
30
30
|
def remove_from_artifact name, options={}, &block
|
31
31
|
type = options[:type]
|
32
|
-
file = existing_file_name(name, type)
|
32
|
+
file = existing_file_name(name, type)
|
33
33
|
File.remove_content_from file, options, &block
|
34
34
|
end
|
35
35
|
|
@@ -37,30 +37,30 @@ module RailsAssist::Artifact::CRUD
|
|
37
37
|
options = last_option(names)
|
38
38
|
type = options[:type]
|
39
39
|
artifacts = names.flatten.select_labels
|
40
|
-
|
40
|
+
|
41
41
|
artifacts.each do |name|
|
42
42
|
file = existing_file_name(name, type)
|
43
43
|
File.remove_content_from file, options, &block
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
46
46
|
alias_hash :remove_from_artifact => :delete_from_artifact, :pluralize => true
|
47
47
|
|
48
48
|
def replace_in_artifact name, options={}, &block
|
49
49
|
type = options[:type]
|
50
|
-
file = existing_file_name(name, type)
|
51
|
-
File.replace_content_from file, options, &block
|
50
|
+
file = existing_file_name(name, type)
|
51
|
+
File.replace_content_from file, options, &block
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def replace_in_artifacts *names, &block
|
55
55
|
options = last_option(names)
|
56
56
|
type = options[:type]
|
57
57
|
artifacts = names.flatten.select_labels
|
58
|
-
|
58
|
+
|
59
59
|
artifacts.each do |name|
|
60
60
|
file = existing_file_name(name, type)
|
61
61
|
File.replace_content_from file, options, &block
|
62
62
|
end
|
63
|
-
end
|
64
|
-
alias_hash :replace_in_artifact => :update_artifact, :pluralize => true
|
65
|
-
end
|
66
|
-
end
|
63
|
+
end
|
64
|
+
alias_hash :replace_in_artifact => :update_artifact, :pluralize => true
|
65
|
+
end
|
66
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'rails_assist/artifact'
|
2
2
|
|
3
3
|
module RailsAssist::Artifact
|
4
|
-
module FileName
|
4
|
+
module FileName
|
5
5
|
include RailsAssist::Artifact::Directory
|
6
6
|
include RailsAssist::Artifact::Path
|
7
7
|
|
8
|
-
def make_file_name name, type, options={}
|
8
|
+
def make_file_name name, type, options={}
|
9
9
|
send :"#{type}_file_name", name, options
|
10
10
|
end
|
11
11
|
|
12
|
-
def existing_file_name name, type=nil, options = {}
|
12
|
+
def existing_file_name name, type=nil, options = {}
|
13
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}"
|
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
19
|
end
|
20
20
|
return result
|
21
21
|
elsif type == :migration
|
22
22
|
raise StandardError, "The method #find_#{type} to find the migration is not available!"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# default for non-migration
|
26
26
|
file_name = make_file_name name, type, options
|
27
27
|
raise IOError, "No file for :#{type} found at location: #{file_name}" if !File.file?(file_name)
|
@@ -33,9 +33,9 @@ module RailsAssist::Artifact
|
|
33
33
|
def existing_#{name}_file name, type=nil, options = {}
|
34
34
|
existing_file_name name, type, options
|
35
35
|
end
|
36
|
-
}
|
36
|
+
}
|
37
37
|
end
|
38
38
|
end # file_name
|
39
|
-
|
39
|
+
|
40
40
|
include FileName
|
41
|
-
end
|
41
|
+
end
|
@@ -4,21 +4,21 @@ module RailsAssist
|
|
4
4
|
def insert_ruby_statement statement, options = {}
|
5
5
|
"<%= #{statement} %>"
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def insert_ruby_block statement, options = {}, &block
|
9
9
|
%Q{"<%= #{statement} %>"
|
10
10
|
#{yield}
|
11
11
|
<% end %>
|
12
12
|
}
|
13
13
|
# insert_content options
|
14
|
-
end
|
14
|
+
end
|
15
15
|
|
16
16
|
def insert_tag tag, attributes, options= {}, &block
|
17
17
|
%Q{"<#{tag} #{attributes}>"
|
18
18
|
#{yield}
|
19
19
|
<#{tag}/>
|
20
20
|
}
|
21
|
-
end
|
21
|
+
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
@@ -4,14 +4,13 @@ module RailsAssist
|
|
4
4
|
def insert_ruby_statement statement, options = {}
|
5
5
|
"\n= #{statement}"
|
6
6
|
end
|
7
|
-
|
8
7
|
def insert_ruby_block statement, options = {}, &block
|
9
8
|
# get indentation of previous line
|
10
9
|
%Q{"<%= #{statement} %>"
|
11
10
|
#{yield}
|
12
11
|
<% end %>
|
13
12
|
}
|
14
|
-
end
|
13
|
+
end
|
15
14
|
|
16
15
|
def insert_tag tag, options= {}, &block
|
17
16
|
attributes = options[:attributes]
|
@@ -20,13 +19,13 @@ module RailsAssist
|
|
20
19
|
#{yield}
|
21
20
|
<#{tag}/>
|
22
21
|
}
|
23
|
-
end
|
24
|
-
|
22
|
+
end
|
23
|
+
|
25
24
|
protected
|
26
|
-
|
25
|
+
|
27
26
|
def format attributes
|
28
27
|
attributes.map{|key, value| ":#{key} => \"#{value}\""}
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
32
|
-
end
|
31
|
+
end
|
@@ -2,14 +2,14 @@ module RailsAssist
|
|
2
2
|
module TemplateLanguage
|
3
3
|
class Slim < Base
|
4
4
|
def insert_ruby_statement statement, options = {}
|
5
|
-
"\n= #{statement}"
|
5
|
+
"\n= #{statement}"
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def insert_ruby_block statement, options = {}, &block
|
9
|
-
end
|
9
|
+
end
|
10
10
|
|
11
11
|
def insert_tag tag, css, options= {}, &block
|
12
|
-
end
|
12
|
+
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
data/rails_artifactor.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.5.
|
7
|
+
s.name = "rails_artifactor"
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = "2011-09-21"
|
13
|
+
s.description = "Helpers for handling Rails 3 artifacts in general, such as CRUD operations etc."
|
14
|
+
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.markdown"
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"VERSION",
|
29
29
|
"lib/rails_artifactor.rb",
|
30
30
|
"lib/rails_artifactor/artifact.rb",
|
31
|
+
"lib/rails_artifactor/artifact/asset_artifact.rb",
|
31
32
|
"lib/rails_artifactor/artifact/base.rb",
|
32
33
|
"lib/rails_artifactor/artifact/crud.rb",
|
33
34
|
"lib/rails_artifactor/artifact/crud/create.rb",
|
@@ -35,6 +36,7 @@ Gem::Specification.new do |s|
|
|
35
36
|
"lib/rails_artifactor/artifact/crud/read.rb",
|
36
37
|
"lib/rails_artifactor/artifact/crud/update.rb",
|
37
38
|
"lib/rails_artifactor/artifact/file_name/artifacts.rb",
|
39
|
+
"lib/rails_artifactor/artifact/file_name/asset.rb",
|
38
40
|
"lib/rails_artifactor/artifact/file_name/view.rb",
|
39
41
|
"lib/rails_artifactor/artifact/markers.rb",
|
40
42
|
"lib/rails_artifactor/artifact/orm.rb",
|
@@ -66,6 +68,7 @@ Gem::Specification.new do |s|
|
|
66
68
|
"spec/fixtures/app/views/layouts/application.erb.html",
|
67
69
|
"spec/fixtures/app/views/layouts/application.html.erb",
|
68
70
|
"spec/rails_artifactor/artifact/base_spec.rb",
|
71
|
+
"spec/rails_artifactor/artifact/crud/asset_spec.rb",
|
69
72
|
"spec/rails_artifactor/artifact/crud/controller_spec.rb",
|
70
73
|
"spec/rails_artifactor/artifact/crud/helper_spec.rb",
|
71
74
|
"spec/rails_artifactor/artifact/crud/mailer_spec.rb",
|
@@ -92,10 +95,10 @@ Gem::Specification.new do |s|
|
|
92
95
|
"spec/rails_artifactor/base/file_name_spec.rb",
|
93
96
|
"spec/spec_helper.rb"
|
94
97
|
]
|
95
|
-
s.homepage =
|
96
|
-
s.require_paths = [
|
97
|
-
s.rubygems_version =
|
98
|
-
s.summary =
|
98
|
+
s.homepage = "http://github.com/kristianmandrup/rails_artifactor"
|
99
|
+
s.require_paths = ["lib"]
|
100
|
+
s.rubygems_version = "1.8.10"
|
101
|
+
s.summary = "Helpers for handling Rails 3 artifacts"
|
99
102
|
|
100
103
|
if s.respond_to? :specification_version then
|
101
104
|
s.specification_version = 3
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'asset API - symbols' do
|
4
|
+
use_helpers :asset
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
RailsAssist::Directory.rails_root = fixtures_dir
|
8
|
+
|
9
|
+
remove_asset :javascript, :edit if has_asset? :account, :edit
|
10
|
+
create_asset :javascript, :edit do
|
11
|
+
"edit me"
|
12
|
+
end
|
13
|
+
|
14
|
+
create_asset :javascript, :show do
|
15
|
+
"show me"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
remove_view :account
|
21
|
+
end
|
22
|
+
|
23
|
+
context "Non-existant view(s)" do
|
24
|
+
|
25
|
+
it "should read application layouts view" do
|
26
|
+
asset_file_name(:javascripts => :edit).should match /edit/
|
27
|
+
read_asset(:javascripts => :edit).should match /edit me/
|
28
|
+
read_asset(:javascripts => :show).should match /show me/
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not fail trying to remove non-existant views" do
|
32
|
+
remove_assets :edit, :show, :folder => :javascripts
|
33
|
+
remove_artifacts :asset, :edit, :show, :folder => :javascripts
|
34
|
+
|
35
|
+
remove_asset :javascripts => :show
|
36
|
+
remove_artifact :asset, :show, :folder => :javascripts
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not find a non-existant asset" do
|
40
|
+
asset_file :show, :folder => :javascripts do |person|
|
41
|
+
fail "should not find asset show!"
|
42
|
+
end
|
43
|
+
|
44
|
+
has_asset?(:show, :folder => :javascripts).should be_false
|
45
|
+
has_assets?(:show, :edit, :folder => :javascripts).should be_false
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not read from non-existant view" do
|
49
|
+
read_asset :javascripts => :show do |content|
|
50
|
+
fail "should not find person content!"
|
51
|
+
end.should_not be_true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'view API - symbols' do
|
4
4
|
use_helpers :view
|
5
5
|
|
6
|
-
before :each do
|
6
|
+
before :each do
|
7
7
|
RailsAssist::Directory.rails_root = fixtures_dir
|
8
8
|
|
9
9
|
remove_view :account, :edit if has_view? :account, :edit
|
@@ -11,7 +11,7 @@ describe 'view API - symbols' do
|
|
11
11
|
%q{
|
12
12
|
<h1><%= title %></h1>
|
13
13
|
}
|
14
|
-
end
|
14
|
+
end
|
15
15
|
|
16
16
|
create_view :layouts, :application do
|
17
17
|
%q{
|
@@ -30,10 +30,10 @@ describe 'view API - symbols' do
|
|
30
30
|
</body>
|
31
31
|
</html>
|
32
32
|
}
|
33
|
-
end
|
33
|
+
end
|
34
34
|
end
|
35
35
|
|
36
|
-
after :each do
|
36
|
+
after :each do
|
37
37
|
remove_view :account
|
38
38
|
end
|
39
39
|
|
@@ -59,27 +59,27 @@ describe 'view API - symbols' do
|
|
59
59
|
remove_view :person => :show
|
60
60
|
remove_artifact :view, :show, :folder => :person
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should not find a non-existant view" do
|
64
64
|
view_file :show, :folder => :person do |person|
|
65
65
|
fail "should not find person view!"
|
66
|
-
end
|
67
|
-
|
66
|
+
end
|
67
|
+
|
68
68
|
has_view?(:show, :folder => :person).should be_false
|
69
69
|
has_views?(:show, :edit, :folder => :person).should be_false
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "should not insert into non-existant view" do
|
73
73
|
insert_into_view(:show, :folder => :person, :after => 'Hello', :content => 'Yes').should_not be_true
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
it "should not read from non-existant view" do
|
77
77
|
read_view :person => :show do |content|
|
78
78
|
fail "should not find person content!"
|
79
79
|
end.should_not be_true
|
80
|
-
end
|
80
|
+
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should have an account_view file that contains an index method and two inserted comments" do
|
84
84
|
insert_into_view :account, :edit, :content => '# hello', :before => '<h1>'
|
85
85
|
insert_into_view :account, :edit, :before => '<h1>' do
|
@@ -88,5 +88,5 @@ describe 'view API - symbols' do
|
|
88
88
|
puts read_view(:account, :edit)
|
89
89
|
read_view(:account, :edit).should have_comment 'hello'
|
90
90
|
end
|
91
|
-
end
|
91
|
+
end
|
92
92
|
|