refinerycms-convertor 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -2,13 +2,14 @@ require 'convertor-tags'
2
2
 
3
3
  class ConvertorFile
4
4
 
5
- attr_reader :original_dir, :original_file, :current_dir, :current_file
5
+ attr_reader :original_dir, :original_file, :current_dir, :current_file, :contents
6
6
 
7
7
  def initialize(path)
8
- @file = File.new(path)
9
-
10
8
  @original_dir = @current_dir = File.dirname(path)
11
9
  @original_file = @current_file = path
10
+
11
+ @contents = File.new(path).read
12
+ @convertor_tag = ConvertorTag.new(@contents)
12
13
  end
13
14
 
14
15
  def copy(path)
@@ -19,4 +20,23 @@ class ConvertorFile
19
20
  @current_file = path
20
21
  end
21
22
 
23
+ def extract_to_partials(destination)
24
+ FileUtils.mkdir_p(destination)
25
+
26
+ @convertor_tag.tags.each do |tag|
27
+ File.open(destination + "_#{tag}.html.erb", "w") do |f|
28
+ f.write @convertor_tag.text_inside_tag(tag)
29
+ find_and_replace(@convertor_tag.text_with_tag(tag), "<%= render :partial => 'shared/#{tag}' %>")
30
+ end
31
+ end
32
+ end
33
+
34
+ def find_and_replace(find, replace)
35
+ @contents.gsub!(find, replace)
36
+
37
+ File.open(@current_file, "w") do |f|
38
+ f.write @contents
39
+ end
40
+ end
41
+
22
42
  end
@@ -5,15 +5,15 @@ class ConvertorTag
5
5
  end
6
6
 
7
7
  def tags
8
- @text.scan(/{@\s*(.*)\s*@}.*{@ \/\1 @}/m).flatten!
8
+ @text.scan(/{@\s*(.*)\s*@}.*{@ \/\1 @}/m).flatten
9
9
  end
10
10
 
11
11
  def text_inside_tag(tag)
12
- @text.match(/{@\s*#{tag}\s*@}\n(.*){@ \/#{tag} @}/m)[1] rescue nil
12
+ @text.match(/{@\s*#{tag}\s*@}(.*){@ \/#{tag} @}/m)[1] rescue nil
13
13
  end
14
14
 
15
15
  def text_with_tag(tag)
16
- @text.match(/{@\s*#{tag}\s*@}\n(.*){@ \/#{tag} @}/m)[0] rescue nil
16
+ @text.match(/{@\s*#{tag}\s*@}(.*){@ \/#{tag} @}/m)[0] rescue nil
17
17
  end
18
18
 
19
19
  end
@@ -19,6 +19,10 @@ class RefinerycmsConvertor
19
19
  ['images', 'javascripts', 'stylesheets', 'views/layouts', 'views/pages', 'views/shared'].each do |dir|
20
20
  FileUtils.mkdir_p(@theme_dir + dir)
21
21
  end
22
+
23
+ @layout = ConvertorLayout.new(@index_html)
24
+
25
+ @layout.extract_to_partials(@theme_dir + "views/shared")
22
26
  end
23
27
 
24
28
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{refinerycms-convertor}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["stevenheidel"]
@@ -34,12 +34,49 @@ describe ConvertorFile do
34
34
 
35
35
  context "#extract_to_partials" do
36
36
 
37
- it "should take out all tags to respective shared files" do
37
+ before(:all) do
38
+ @extractor_html = ConvertorFile.new(Rails.root.join('themes', 'theme', 'original', 'index.html'))
39
+ @extractor_html.copy(Rails.root.join('themes', 'theme', 'temp', 'extractor.html'))
38
40
 
41
+ @convertor_tag = ConvertorTag.new(@extractor_html.contents)
42
+
43
+ @extractor_html.extract_to_partials(Rails.root.join('themes', 'theme', 'views', 'extractor'))
44
+ end
45
+
46
+ it "should copy all tags to respective shared files" do
47
+ @convertor_tag.tags.each do |tag|
48
+ partial = Rails.root.join('themes', 'theme', 'views', 'extractor', "_#{tag}.html.erb")
49
+
50
+ File.should be_exist(partial)
51
+ File.new(partial).read.should == @convertor_tag.text_inside_tag(tag)
52
+ end
53
+ end
54
+
55
+ it "should remove tags from original file" do
56
+ @convertor_tag.tags.each do |tag|
57
+ @extractor_html.contents.include?(@convertor_tag.text_with_tag(tag)).should be_false
58
+ end
59
+ end
60
+
61
+ it "should add render partial lines" do
62
+ @convertor_tag.tags.each do |tag|
63
+ @extractor_html.contents.include?("<%= render :partial => '#{tag}' %>").should be_true
64
+ end
39
65
  end
40
66
 
41
67
  it "should take the <head> to shared/_head.html.erb" do
42
68
  pending
69
+ end
70
+
71
+ after(:all) do
72
+ # Deletes the directories created, comment out if debugging
73
+ Dir.glob(Rails.root.join('themes', 'theme') + '**/**').reverse.each do |f|
74
+ begin
75
+ File.delete(f) unless f =~ /original/
76
+ rescue
77
+ Dir.delete(f)
78
+ end if f.include?(Rails.root.join('themes', 'theme').to_s)
79
+ end# if false
43
80
  end
44
81
 
45
82
  end
@@ -1,6 +1,58 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <body>
4
- <p>Hello World!</p>
5
- </body>
6
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>Site Title | Page Title</title>
5
+ <meta name="description" content="This is a description of the site. There are many things on it." />
6
+ <meta name="keywords" content="keyword, keyword, keyword, that's all you ever talk about" />
7
+ <meta name="robots" content="nofollow,index" />
8
+
9
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
10
+ <link href="homepage_stylesheet.css" rel="stylesheet" type="text/css" />
11
+ <script type="text/javascript" src="jquery-1.4.2.min.js" ></script>
12
+ </head>
13
+ <body>
14
+
15
+ <div class="header">
16
+ {@ header @}
17
+ <div class="inner">
18
+ <div class="left-header">
19
+ {@ menu @}
20
+ <div id="container">
21
+ <ul id="menu">
22
+ <li><a href="#">Menu #1</a></li>
23
+ <li><a href="#">Menu #2</a>
24
+ <div>
25
+ <ul>
26
+ <li><a href="#">Submenu #1</a></li>
27
+ <li><a href="#">Submenu #2</a></li>
28
+ <li><a href="#">Submenu #3</a></li>
29
+ </ul>
30
+ </div>
31
+ </li>
32
+ </ul>
33
+ <img src="logo.png" alt="home innovation" />
34
+ </div>
35
+ {@ /menu @}
36
+ </div>
37
+ </div>
38
+ {@ /header @}
39
+ <div class="main">
40
+ {@ content_page @}
41
+ <div class="left">
42
+
43
+ </div>
44
+ {@ /content_page @}
45
+
46
+ </div>
47
+ {@ footer @}
48
+ <div class="footer">
49
+ <div align="left">
50
+ <p align="center"><a href="#">Home</a> | <a href="#">About</a> | <a href="#">Contact</a></p>
51
+ <p align="center">© Copyright 2010 RefineryCMS Convertor</p>
52
+ </div>
53
+ </div>
54
+ {@ /footer @}
55
+ </div>
56
+ </div>
57
+ </body>
58
+ </html>
@@ -44,7 +44,7 @@ describe RefinerycmsConvertor do
44
44
  rescue
45
45
  Dir.delete(f)
46
46
  end if f.include?(@theme.theme_dir.to_s)
47
- end
47
+ end# if false
48
48
  end
49
49
 
50
50
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
-
8
+ config.after(:all) {}
9
9
  end
10
10
 
11
11
  require 'fileutils'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - stevenheidel