Commit f4aa37844caf926fa644ab3109aac54386aa2353
1 parent
53a345b6
Exists in
master
and in
29 other branches
Running the tests does not depend on compiling translations anymore.
Showing
4 changed files
with
51 additions
and
5 deletions
Show diff stats
app/models/doc_section.rb
1 | 1 | class DocSection < DocItem |
2 | 2 | |
3 | + def self.root_dir | |
4 | + @root_dir ||= File.join(RAILS_ROOT, 'doc', 'noosfero') | |
5 | + end | |
6 | + | |
3 | 7 | def items |
4 | 8 | @items ||= load_items |
5 | 9 | end |
... | ... | @@ -36,7 +40,7 @@ class DocSection < DocItem |
36 | 40 | |
37 | 41 | def self.root(language = 'en') |
38 | 42 | @root ||= {} |
39 | - @root[language] ||= load(File.join(RAILS_ROOT, 'doc', 'noosfero'), language) | |
43 | + @root[language] ||= load(root_dir, language) | |
40 | 44 | end |
41 | 45 | |
42 | 46 | private |
... | ... | @@ -44,7 +48,7 @@ class DocSection < DocItem |
44 | 48 | attr_accessor :directory |
45 | 49 | |
46 | 50 | def self.load_dirs(language) |
47 | - Dir.glob(File.join(RAILS_ROOT, 'doc', 'noosfero', '*')).select {|item| File.directory?(item) }.map do |dir| | |
51 | + Dir.glob(File.join(root_dir, '*')).select {|item| File.directory?(item) }.map do |dir| | |
48 | 52 | load(dir, language) |
49 | 53 | end |
50 | 54 | end | ... | ... |
lib/tasks/doc.rake
... | ... | @@ -86,18 +86,22 @@ namespace :noosfero do |
86 | 86 | end |
87 | 87 | end |
88 | 88 | |
89 | + desc "Build Noosfero online documentation" | |
89 | 90 | task :build => po4a_conf do |
90 | 91 | sh "po4a #{po4a_conf}" |
91 | 92 | end |
92 | 93 | |
94 | + desc "Cleans Noosfero online documentation" | |
93 | 95 | task :clean do |
94 | 96 | sh 'rm -f doc/noosfero/*.xhtml' |
95 | 97 | sh 'rm -f doc/noosfero/*/*.xhtml' |
96 | 98 | rm_f po4a_conf |
97 | 99 | end |
98 | 100 | |
101 | + desc "Rebuild Noosfero online documentation" | |
99 | 102 | task :rebuild => [:clean, :build] |
100 | 103 | |
104 | + desc "Translates Noosfero online documentation (does not touch PO files)" | |
101 | 105 | task :translate => english_xhtml do |
102 | 106 | languages = Noosfero.locales.keys - ['en'] |
103 | 107 | languages.each do |lang| | ... | ... |
lib/tasks/test.rake
test/unit/doc_section_test.rb
1 | 1 | require 'test_helper' |
2 | 2 | |
3 | 3 | class DocSectionTest < ActiveSupport::TestCase |
4 | + | |
5 | + ROOT = File.join(Rails.root, "test", "tmp", "doc") | |
6 | + | |
7 | + def create_doc(section, topic, language, title) | |
8 | + dir = File.join(ROOT, section) | |
9 | + FileUtils.mkdir_p(dir) | |
10 | + File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | |
11 | + f.puts "<h1>#{title}</h1>" | |
12 | + end | |
13 | + end | |
14 | + | |
15 | + def setup | |
16 | + FileUtils.mkdir_p(ROOT) | |
17 | + | |
18 | + # root | |
19 | + create_doc('', 'index', 'en', 'Root') | |
20 | + create_doc('', 'toc', 'en', 'Root') | |
21 | + # cms | |
22 | + create_doc('cms', 'index', 'en', 'Content Management') | |
23 | + create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | |
24 | + create_doc('cms', 'toc', 'en', '') | |
25 | + create_doc('cms', 'toc', 'pt', '') | |
26 | + create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | |
27 | + create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | |
28 | + create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | |
29 | + create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | |
30 | + # user | |
31 | + create_doc('user', 'index', 'en', 'User features') | |
32 | + create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | |
33 | + create_doc('user', 'toc', 'en', '') | |
34 | + create_doc('user', 'toc', 'pt', '') | |
35 | + create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | |
36 | + | |
37 | + DocSection.stubs(:root_dir).returns(ROOT) | |
38 | + end | |
39 | + | |
40 | + def tear_down | |
41 | + FileUtils.rm_rf(ROOT) | |
42 | + end | |
43 | + | |
4 | 44 | should 'be a DocItem' do |
5 | 45 | assert_kind_of DocItem, DocSection.new |
6 | 46 | end |
... | ... | @@ -87,7 +127,7 @@ class DocSectionTest < ActiveSupport::TestCase |
87 | 127 | should 'load null section (the root)' do |
88 | 128 | [nil, ''].each do |key| |
89 | 129 | section = DocSection.find(nil) |
90 | - assert_equal "#{RAILS_ROOT}/doc/noosfero", section.send(:directory) | |
130 | + assert_equal DocSection.root_dir, section.send(:directory) | |
91 | 131 | end |
92 | 132 | end |
93 | 133 | ... | ... |