hayde 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/hayde.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hayde}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Zaharenkov"]
12
- s.date = %q{2010-05-14}
12
+ s.date = %q{2010-05-18}
13
13
  s.description = %q{Helper for generating guides articles from textile source. Extracted from railties-3.0.0.beta3 project. }
14
14
  s.email = %q{ZaharenkovRoman@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,11 +26,13 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "hayde.gemspec",
28
28
  "lib/hayde.rb",
29
+ "lib/hayde/file_utils.rb",
29
30
  "lib/hayde/generator.rb",
30
31
  "lib/hayde/helpers.rb",
31
32
  "lib/hayde/indexer.rb",
32
33
  "lib/hayde/levenshtein.rb",
33
34
  "lib/hayde/textile_extensions.rb",
35
+ "lib/tasks/haydetasks.rb",
34
36
  "test/helper.rb",
35
37
  "test/test_hayde.rb"
36
38
  ]
@@ -0,0 +1,55 @@
1
+ # ---------------------------------------------------------------------------
2
+ #
3
+ # This mixin adds some helper methods for file manipulation.
4
+ #
5
+ # ---------------------------------------------------------------------------
6
+
7
+ module Hayde
8
+ module Utils
9
+ module Files
10
+ def self.included(base)
11
+
12
+ # File list method adds accessor to specified attributes that behaves like FileList.
13
+ # I can specify attribute and use it like FileList instance to
14
+ # include and exclude files, iterate throught file collection.
15
+ #
16
+ # &names - names of attributes
17
+ #
18
+ # Example:
19
+ #
20
+ # class SomeClass
21
+ # include Hayde::Utils::Files
22
+ #
23
+ # filelist_attribute :sources
24
+ # end
25
+ #
26
+ # x = SomeClass.new
27
+ # x.sources.include 'lib/**/*.rb'
28
+ # x.sources.exclude 'doc/**/*'
29
+ # x.each do |file|
30
+ # puts file
31
+ # end
32
+ #
33
+ def base.filelist_attribute(*names)
34
+ names.each do |name|
35
+ define_method "#{name}" do
36
+ files = instance_variable_get("@#{name}_files")
37
+ if !files
38
+ files = FileList.new()
39
+ instance_variable_set("@#{name}_files", files)
40
+ end
41
+ files
42
+ end
43
+
44
+ define_method "#{name}=" do |files|
45
+ if files && files.class != FileList
46
+ files = FileList.new(files)
47
+ end
48
+ instance_variable_set("@#{name}_files", files)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -43,49 +43,42 @@ require 'action_view'
43
43
  require 'hayde/indexer'
44
44
  require 'hayde/helpers'
45
45
  require 'hayde/levenshtein'
46
+ require 'hayde/file_utils'
46
47
 
47
48
  module Hayde
48
- class Generator
49
- # TODO: Move method to utils mudule.
50
- def self.filelist_attribute(*names)
51
- names.each do |name|
52
- define_method "#{name}" do
53
- files = instance_variable_get("@#{name}_files")
54
- if !files
55
- files = FileList.new()
56
- instance_variable_set("@#{name}_files", files)
57
- end
58
- files
59
- end
60
-
61
- define_method "#{name}=" do |files|
62
- instance_variable_set("@#{name}_files", FileList[files])
63
- if files && files.class != FileList
64
- files = FileList.new(files)
65
- end
66
- end
67
- end
68
- end
49
+ class Generator
50
+ include Hayde::Utils::Files
69
51
 
70
- attr_accessor :output_dir, :assets_dir, :warnings, :edge, :force, :layout
52
+ attr_accessor :output_dir, :assets_dir, :warnings, :edge, :force, :layout
71
53
  filelist_attribute :sources
72
54
 
73
55
  GUIDES_RE = /\.(?:textile|html\.erb)$/
74
56
 
75
57
  def initialize(output = nil)
76
- initialize_output_dir(output)
58
+ set_defaults(output)
77
59
  yield self if block_given?
78
60
  end
79
61
 
80
62
  def generate
63
+ puts "Generating guides has been started."
81
64
  generate_guides
65
+ puts "Copying assets ..."
82
66
  copy_assets
67
+ puts "Generating guides has been finished."
68
+ end
69
+
70
+ def clean
71
+ FileUtils.rm_r Dir.glob(File.join(output_dir, '*'))
83
72
  end
84
73
 
85
74
  private
86
75
 
87
- def initialize_output_dir(output)
88
- @output_dir = output || File.join(File.dirname(__FILE__), "docs", "guides")
76
+ def set_defaults(output)
77
+ root_dir = Rails.root if defined? Rails
78
+ root_dir ||= Dir.pwd
79
+ @layout = 'layout'
80
+ @assets_dir = File.join(root_dir, 'guides', 'assets')
81
+ @output_dir = output || File.join(root_dir, 'docs', 'guides')
89
82
  FileUtils.mkdir_p(@output_dir)
90
83
  end
91
84
 
@@ -97,7 +90,7 @@ module Hayde
97
90
  end
98
91
 
99
92
  def copy_assets
100
- FileUtils.cp_r(Dir.glob("#{assets_dir}/*"), output_dir)
93
+ FileUtils.cp_r(Dir.glob(File.join(assets_dir, '*')), output_dir)
101
94
  end
102
95
 
103
96
  def output_file_for(source)
@@ -110,20 +103,20 @@ module Hayde
110
103
  end
111
104
 
112
105
  def generate_guide(source, output)
113
- puts "Generating #{output}"
106
+ puts "Generating #{output} ..."
114
107
  File.open(output, 'w') do |f|
115
108
  view = ActionView::Base.new(File.dirname(source), :edge => edge)
116
109
  view.extend(Helpers)
117
110
 
118
111
  if source =~ /\.html\.erb$/
119
112
  # Generate the special pages like the home.
120
- result = view.render(:layout => 'layout', :file => source)
113
+ result = view.render(:layout => layout, :file => source)
121
114
  else
122
115
  body = File.read(source)
123
116
  body = set_header_section(body, view)
124
117
  body = set_index(body, view)
125
118
 
126
- result = view.render(:layout => 'layout', :text => textile(body))
119
+ result = view.render(:layout => layout, :text => textile(body))
127
120
 
128
121
  warn_about_broken_links(result) if warnings
129
122
  end
data/lib/hayde.rb CHANGED
@@ -24,10 +24,6 @@ rescue Gem::LoadError
24
24
  exit 1
25
25
  end
26
26
 
27
- module Hayde
28
- require 'hayde/textile_extensions'
29
- require 'hayde/generator'
30
-
31
- RedCloth.send(:include, Hayde::TextileExtensions)
32
- #Hayde::Generator.new.generate
33
- end
27
+ require 'hayde/generator'
28
+
29
+ Dir.glob(File.join(pwd, 'tasks', '*.rb')).each { |task| require task }
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+
4
+ CLOBBER.include('docs/guides')
5
+
6
+ namespace :hayde do
7
+ desc "Generates guides documentation."
8
+ task :build do
9
+ guides_generator = Hayde::Generator.new do |g|
10
+ g.sources.include 'guides/source/**/*'
11
+ g.sources.exclude 'guides/source/layout.*'
12
+ end
13
+ guides_generator.generate
14
+ end
15
+
16
+ desc "Generates guides documentation."
17
+ task :rebuild do
18
+ guides_generator = Hayde::Generator.new do |g|
19
+ g.sources.include 'guides/source/**/*'
20
+ g.sources.exclude 'guides/source/layout.*'
21
+ g.force = true
22
+ end
23
+ guides_generator.generate
24
+ end
25
+
26
+ desc "Removes generated guides."
27
+ task :clean do
28
+ guides_generator = Hayde::Generator.new
29
+ guides_generator.clean
30
+ end
31
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hayde
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roman Zaharenkov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-14 00:00:00 +03:00
18
+ date: 2010-05-18 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -84,11 +84,13 @@ files:
84
84
  - VERSION
85
85
  - hayde.gemspec
86
86
  - lib/hayde.rb
87
+ - lib/hayde/file_utils.rb
87
88
  - lib/hayde/generator.rb
88
89
  - lib/hayde/helpers.rb
89
90
  - lib/hayde/indexer.rb
90
91
  - lib/hayde/levenshtein.rb
91
92
  - lib/hayde/textile_extensions.rb
93
+ - lib/tasks/haydetasks.rb
92
94
  - test/helper.rb
93
95
  - test/test_hayde.rb
94
96
  has_rdoc: true