pupu 0.1.pre → 0.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.
Files changed (141) hide show
  1. data/.gitignore +9 -0
  2. data/CHANGELOG +23 -4
  3. data/Gemfile +9 -0
  4. data/LICENSE +1 -1
  5. data/README.textile +3 -3
  6. data/TODO.txt +8 -3
  7. data/bin/pupu +19 -24
  8. data/examples/merb/.gitignore +17 -0
  9. data/examples/merb/Gemfile +27 -0
  10. data/examples/merb/README.textile +3 -5
  11. data/examples/merb/Rakefile +3 -3
  12. data/examples/merb/config/framework.rb +4 -4
  13. data/examples/merb/config/init.rb +7 -0
  14. data/examples/merb/public/pupu/autocompleter/.gitignore +5 -0
  15. data/examples/merb/public/pupu/autocompleter/README.textile +2 -2
  16. data/examples/merb/public/pupu/autocompleter/config.rb +1 -1
  17. data/examples/merb/public/pupu/blueprint/.gitignore +5 -0
  18. data/examples/merb/public/pupu/blueprint/config.rb +7 -7
  19. data/examples/merb/public/pupu/flash/.gitignore +5 -0
  20. data/examples/merb/public/pupu/flash/config.rb +1 -1
  21. data/examples/merb/public/pupu/lighter/.gitignore +10 -0
  22. data/examples/merb/public/pupu/lighter/config.rb +2 -2
  23. data/{spec/pupu/adapters/merb_spec.rb → examples/merb/public/pupu/lighter/images/.gitignore} +0 -0
  24. data/examples/merb/public/pupu/mootools/.gitignore +5 -0
  25. data/examples/merb/public/pupu/mootools/README.textile +1 -1
  26. data/examples/merb/public/pupu/mootools/config.rb +1 -1
  27. data/examples/rails/.gitignore +7 -0
  28. data/examples/rails/Gemfile +28 -0
  29. data/examples/rails/README.textile +5 -0
  30. data/examples/rails/Rakefile +10 -0
  31. data/examples/rails/app/controllers/application_controller.rb +10 -0
  32. data/examples/rails/app/controllers/home_controller.rb +8 -0
  33. data/examples/rails/app/helpers/application_helper.rb +3 -0
  34. data/{spec/pupu/adapters/rango_spec.rb → examples/rails/app/views/examples/arguments.html.erb} +0 -0
  35. data/examples/rails/app/views/examples/dependencies.html.erb +0 -0
  36. data/examples/rails/app/views/examples/simple.html.erb +4 -0
  37. data/examples/rails/app/views/index.html.erb +7 -0
  38. data/examples/rails/app/views/layout.html.erb +12 -0
  39. data/examples/rails/config/boot.rb +110 -0
  40. data/examples/rails/config/environment.rb +55 -0
  41. data/examples/rails/config/environments/development.rb +17 -0
  42. data/examples/rails/config/environments/production.rb +28 -0
  43. data/examples/rails/config/environments/test.rb +28 -0
  44. data/examples/rails/config/initializers/backtrace_silencers.rb +7 -0
  45. data/examples/rails/config/initializers/inflections.rb +10 -0
  46. data/examples/rails/config/initializers/mime_types.rb +5 -0
  47. data/examples/rails/config/initializers/new_rails_defaults.rb +21 -0
  48. data/examples/rails/config/initializers/session_store.rb +15 -0
  49. data/examples/rails/config/routes.rb +43 -0
  50. data/examples/rails/db/seeds.rb +7 -0
  51. data/examples/rails/public/404.html +30 -0
  52. data/examples/rails/public/422.html +30 -0
  53. data/examples/rails/public/500.html +30 -0
  54. data/examples/rails/public/favicon.ico +0 -0
  55. data/examples/rails/public/robots.txt +5 -0
  56. data/examples/rails/script/about +4 -0
  57. data/examples/rails/script/console +3 -0
  58. data/examples/rails/script/dbconsole +3 -0
  59. data/examples/rails/script/destroy +3 -0
  60. data/examples/rails/script/generate +3 -0
  61. data/examples/rails/script/performance/benchmarker +3 -0
  62. data/examples/rails/script/performance/profiler +3 -0
  63. data/examples/rails/script/plugin +3 -0
  64. data/examples/rails/script/runner +3 -0
  65. data/examples/rails/script/server +3 -0
  66. data/examples/rails/spec/application_spec.rb +37 -0
  67. data/examples/rails/spec/spec_helper.rb +0 -0
  68. data/examples/rango/.gitignore +4 -0
  69. data/examples/rango/Gemfile +56 -0
  70. data/examples/rango/README.textile +4 -6
  71. data/examples/rango/init.rb +7 -0
  72. data/examples/rango/media/pupu/autocompleter/.gitignore +5 -0
  73. data/examples/rango/media/pupu/autocompleter/README.textile +2 -2
  74. data/examples/rango/media/pupu/autocompleter/config.rb +1 -1
  75. data/examples/rango/media/pupu/blueprint/.gitignore +5 -0
  76. data/examples/rango/media/pupu/blueprint/config.rb +7 -7
  77. data/examples/rango/media/pupu/flash/.gitignore +5 -0
  78. data/examples/rango/media/pupu/flash/config.rb +1 -1
  79. data/examples/rango/media/pupu/lighter/.gitignore +10 -0
  80. data/examples/rango/media/pupu/lighter/config.rb +2 -2
  81. data/examples/rango/media/pupu/lighter/images/.gitignore +0 -0
  82. data/examples/rango/media/pupu/mootools/.gitignore +5 -0
  83. data/examples/rango/media/pupu/mootools/README.textile +1 -1
  84. data/examples/rango/media/pupu/mootools/config.rb +1 -1
  85. data/gems/cache/media-path-0.1.2.gem +0 -0
  86. data/gems/cache/nake-0.0.8.gem +0 -0
  87. data/gems/cache/rspec-1.3.0.gem +0 -0
  88. data/gems/cache/term-ansicolor-1.0.4.gem +0 -0
  89. data/lib/pupu.rb +2 -1
  90. data/lib/pupu/adapters/merb.rb +12 -0
  91. data/lib/pupu/adapters/rails.rb +12 -0
  92. data/lib/pupu/adapters/rango.rb +25 -3
  93. data/lib/pupu/cli.rb +13 -11
  94. data/lib/pupu/dsl.rb +34 -13
  95. data/lib/pupu/exceptions.rb +5 -0
  96. data/lib/pupu/github.rb +26 -14
  97. data/lib/pupu/helpers.rb +8 -2
  98. data/lib/pupu/metadata.rb +2 -0
  99. data/lib/pupu/parser.rb +19 -4
  100. data/lib/pupu/pupu.rb +53 -27
  101. data/lib/pupu/tasks/pupu.nake +52 -0
  102. data/lib/pupu/version.rb +1 -3
  103. data/pupu.gemspec +15 -7
  104. data/pupu.pre.gemspec +5 -33
  105. data/spec/data/public/pupu/autocompleter/.gitignore +5 -0
  106. data/spec/data/public/pupu/autocompleter/README.textile +2 -2
  107. data/spec/data/public/pupu/autocompleter/config.rb +3 -1
  108. data/spec/pupu/dsl_spec.rb +3 -0
  109. data/spec/pupu/exceptions_spec.rb +3 -0
  110. data/spec/pupu/github_spec.rb +4 -1
  111. data/spec/pupu/helpers_spec.rb +5 -2
  112. data/spec/pupu/metadata_spec.rb +3 -0
  113. data/spec/pupu/parser_spec.rb +4 -1
  114. data/spec/pupu/pupu_spec.rb +3 -0
  115. data/stubs/pupu/content/%name%.gemspec.rbt +47 -0
  116. data/stubs/pupu/content/%name%.pre.gemspec.rbt +8 -0
  117. data/stubs/pupu/content/.gitignore +12 -0
  118. data/stubs/pupu/content/config.rb.rbt +3 -1
  119. data/stubs/pupu/content/deps.rip +5 -0
  120. data/stubs/pupu/content/images/.gitignore +0 -0
  121. data/stubs/pupu/content/init.rb.rbt +17 -0
  122. data/stubs/pupu/content/lib/%name%.rb.rbt +4 -0
  123. data/stubs/pupu/content/lib/%name%/adapters/rails.rb +0 -0
  124. data/stubs/pupu/content/lib/%name%/adapters/rango.rb +0 -0
  125. data/stubs/pupu/content/spec/%name%/.gitignore +0 -0
  126. data/stubs/pupu/content/spec/%name%_spec.rb.rbt +10 -0
  127. data/stubs/pupu/content/spec/spec.opts +5 -0
  128. data/stubs/pupu/content/spec/spec_helper.rb.rbt +7 -0
  129. data/stubs/pupu/postprocess.rb +8 -0
  130. data/stubs/pupu/setup.rb +4 -0
  131. data/tasks.rb +37 -0
  132. metadata +284 -200
  133. data/Rakefile +0 -28
  134. data/script/spec +0 -14
  135. data/tasks/benchmark.rake +0 -11
  136. data/tasks/gem.rake +0 -23
  137. data/tasks/hooks.rake +0 -12
  138. data/tasks/release.rake +0 -68
  139. data/tasks/spec.rake +0 -27
  140. data/tasks/submodules.rake +0 -33
  141. data/tasks/yardoc.rake +0 -9
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "fileutils"
2
4
  require "yaml"
3
5
  require "ostruct"
@@ -7,7 +9,7 @@ require "pupu/pupu"
7
9
  require "pupu/github"
8
10
 
9
11
  # copyied from merb.thor, this part is actually my code as well :)
10
- module ColorfulMessages
12
+ module Kernel
11
13
  # red
12
14
  def error(*messages)
13
15
  puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" }
@@ -38,16 +40,15 @@ end
38
40
 
39
41
  module Pupu
40
42
  class CLI
41
- include ColorfulMessages
42
- attr_reader :args
43
- def initialize(args)
44
- @args = args
43
+ attr_reader :args, :options
44
+ def initialize(args, options = Hash.new)
45
+ @args, @options = args, options
45
46
  self.detect
46
47
  self.load_config
47
48
  self.parse_argv
48
49
  self.check_setup
49
50
  note "Using media directory: #{::Pupu.media_root}"
50
- note "Using strategy: #{Pupu.strategy}"
51
+ note "Using strategy: #{::Pupu.strategy}"
51
52
  end
52
53
 
53
54
  def parse_argv
@@ -62,7 +63,7 @@ module Pupu
62
63
  elsif argument.match(/--strategy=(.+)/)
63
64
  self.args.delete(argument)
64
65
  if %[copy submodules].include?($1)
65
- Pupu.strategy = $1.to_sym
66
+ ::Pupu.strategy = $1.to_sym
66
67
  else
67
68
  abort "Available strategies: copy, submodules"
68
69
  end
@@ -76,7 +77,7 @@ module Pupu
76
77
  path ||= ["media", "public"].find { |directory| File.directory?(directory) }
77
78
  return if path.nil?
78
79
  ::Pupu.media_root = File.expand_path(path)
79
- Pupu.strategy ||= :copy
80
+ ::Pupu.strategy ||= :copy
80
81
  end
81
82
 
82
83
  def check_setup
@@ -86,8 +87,9 @@ module Pupu
86
87
  def install
87
88
  self.args.each do |pupu|
88
89
  begin
89
- GitHub.install(pupu)
90
- rescue PluginIsAlreadyInstalled
90
+ GitHub.install(pupu, options)
91
+ rescue PluginIsAlreadyInstalled => e
92
+ puts e.backtrace.join("\n- ")
91
93
  info "Plugin #{pupu} is already installed, skipping"
92
94
  end
93
95
  end
@@ -146,7 +148,7 @@ module Pupu
146
148
  # search on github
147
149
  require "yaml"
148
150
  require "open-uri"
149
- open("http://github.com/api/v1/yaml/search/pupu") do |stream|
151
+ open("https://github.com/api/v1/yaml/search/pupu") do |stream|
150
152
  repositories = YAML::load(stream.read)["repositories"]
151
153
  repositories.each do |repository|
152
154
  repository = OpenStruct.new(repository)
@@ -1,5 +1,8 @@
1
+ # encoding: utf-8
2
+
1
3
  require "ostruct"
2
4
  require "media-path"
5
+ require "pupu/parser"
3
6
 
4
7
  class Hash
5
8
  def to_html_attrs
@@ -9,12 +12,19 @@ end
9
12
 
10
13
  module Pupu
11
14
  class DSL
12
- attr_reader :output, :files, :path
13
- def initialize(pupu)
14
- @pupu = pupu
15
+ attr_reader :output, :path
16
+
17
+ def files
18
+ @page.files
19
+ end
20
+
21
+ def initialize(pupu, page = Page.new)
22
+ @pupu = pupu
23
+ @page = page
15
24
  @output = Array.new
16
- @files = Array.new
25
+ @files = files
17
26
  @dependencies = Array.new
27
+ puts "DSL: #{page.inspect}"
18
28
  @path = pupu.file("config.rb")
19
29
  end
20
30
 
@@ -49,17 +59,28 @@ module Pupu
49
59
  def javascript(basename, params = Hash.new)
50
60
  path = @pupu.javascript(basename).url
51
61
  tag = "<script src='#{path}' type='text/javascript'></script>"
52
- @files.push(path)
53
- @output.push(tag)
62
+ if params[:if]
63
+ tag = "<!--[if #{params[:if]}]>" + tag + "<![endif]-->"
64
+ end
65
+ unless files.include?(path)
66
+ files.push(path)
67
+ @output.push(tag)
68
+ end
54
69
  end
55
70
 
56
71
  def stylesheet(basename, params = Hash.new)
57
72
  path = @pupu.stylesheet(basename).url
73
+ condition = params.delete(:if)
58
74
  default = {media: 'screen', rel: 'stylesheet', type: 'text/css'}
59
75
  params = default.merge(params)
60
76
  tag = "<link href='#{path}' #{params.to_html_attrs} />"
61
- @files.push(path)
62
- @output.push(tag)
77
+ if condition
78
+ tag = "<!--[if #{condition}]>" + tag + "<![endif]-->"
79
+ end
80
+ unless files.include?(path)
81
+ files.push(path)
82
+ @output.push(tag)
83
+ end
63
84
  end
64
85
 
65
86
  def javascripts(*names)
@@ -74,7 +95,7 @@ module Pupu
74
95
  end
75
96
  end
76
97
 
77
- # parameter :type, :optional => ["local", "request"] do |type|
98
+ # parameter :type, optional: ["local", "request"] do |type|
78
99
  # javascript "autocompleter.#{type}"
79
100
  # end
80
101
 
@@ -82,11 +103,11 @@ module Pupu
82
103
  # javascript "mootools-1.2-more" if boolean
83
104
  # end
84
105
  def parameter(name, params = Hash.new, &block)
85
- # pupu :autocompleter, :type => "request"
86
- # @pupu.params: { :type => "request" }
106
+ # pupu :autocompleter, type: "request"
107
+ # @pupu.params: { type: "request" }
87
108
 
88
- # pupu :mootools, :more => true
89
- # @pupu.params: { :more => true }
109
+ # pupu :mootools, more: true
110
+ # @pupu.params: { more: true }
90
111
  if @pupu.params.key?(name)
91
112
  block.call(@pupu.params[name])
92
113
  end
@@ -1,8 +1,13 @@
1
+ # encoding: utf-8
2
+
1
3
  module Pupu
2
4
  class PupuRootNotFound < StandardError
3
5
  end
4
6
 
5
7
  class PluginNotFoundError < StandardError
8
+ def initialize(plugin)
9
+ super("Plugin not found: #{plugin.inspect}")
10
+ end
6
11
  end
7
12
 
8
13
  class PluginIsAlreadyInstalled < StandardError
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "fileutils"
2
4
  require "yaml"
3
5
  require "ostruct"
@@ -7,7 +9,7 @@ require "pupu/exceptions"
7
9
 
8
10
  module ShellExtensions
9
11
  def run(command)
10
- puts "[SHELL] #{command}"
12
+ puts "[SHELL] #{command} # in #{Dir.pwd}"
11
13
  %x(#{command})
12
14
  $?.exitstatus == 0
13
15
  end
@@ -19,20 +21,21 @@ module Pupu
19
21
  class << self
20
22
  include ShellExtensions
21
23
  # GitHub.install("autocompleter")
22
- # GitHub.install("botanicus/autocompleter")
23
- def install(repo)
24
+ # GitHub.install("botanicus/autocompleter", force: true)
25
+ def install(repo, options = Hash.new)
24
26
  user, repo = repo.split("/") if repo.match(%r{/})
25
27
  user = ENV["USER"] unless user
26
28
  url = "git://github.com/#{user}/pupu-#{repo}.git"
27
- self.install_files(repo, url)
28
- self.install_dependencies(@pupu)
29
+ info "Installing #{repo}"
30
+ self.install_files(repo, url, options)
31
+ self.install_dependencies(@pupu, options)
29
32
  # TODO: git commit [files] -m "Added pupu #{repo} from #{url}"
30
33
  end
31
34
 
32
35
  def update(pupu_name)
33
36
  if pupu_name
34
37
  pupu = Pupu[pupu_name]
35
- if Pupu.strategy.eql?(:submodules)
38
+ if ::Pupu.strategy.eql?(:submodules)
36
39
  puts %(git fetch)
37
40
  puts %(git reset origin/master --hard)
38
41
  else
@@ -63,7 +66,7 @@ module Pupu
63
66
  revision = %x(git log | head -1).chomp.sub(/^commit /, "")
64
67
  dsl = DSL.new(pupu)
65
68
  dependencies = dsl.get_dependencies.map { |dependency| dependency.name }
66
- params = {:revision => revision, :repozitory => url, :dependencies => dependencies}
69
+ params = {revision: revision, repozitory: url, dependencies: dependencies}
67
70
  Dir.chdir(@pupu.root.to_s) do
68
71
  File.open("metadata.yml", "w") do |file|
69
72
  file.puts(params.to_yaml)
@@ -71,17 +74,26 @@ module Pupu
71
74
  end
72
75
  end
73
76
 
74
- def install_dependencies(pupu)
77
+ def install_dependencies(pupu, options = Hash.new)
75
78
  dsl = DSL.new(pupu)
76
79
  dsl.instance_eval(File.read(pupu.file("config.rb").path))
77
80
  dsl.get_dependencies.each do |dependency|
78
- self.install(dependency.name.to_s) # FIXME: "user/repo"
81
+ begin
82
+ info "Installing dependency #{dependency}"
83
+ self.install(dependency.name.to_s, options) # FIXME: "user/repo"
84
+ rescue PluginIsAlreadyInstalled => exception
85
+ puts "~ #{exception.message}"
86
+ end
79
87
  end
80
88
  end
81
89
 
82
- def install_files(repo, url)
90
+ def install_files(repo, url, options = Hash.new)
83
91
  chdir do |media_dir|
84
- raise PluginIsAlreadyInstalled if File.directory?(repo) # TODO: custom exception class
92
+ if File.directory?(repo) && !options[:force]
93
+ raise PluginIsAlreadyInstalled, "Pupu #{repo} already exist"
94
+ elsif File.directory?(repo) && options[:force]
95
+ FileUtils.rm_r(repo)
96
+ end
85
97
  run("git clone #{url} #{repo}") || abort("Git failed")
86
98
  Dir.chdir(repo) do
87
99
  proceed_files(repo, url)
@@ -104,7 +116,7 @@ module Pupu
104
116
  end
105
117
  @pupu = Pupu[repo]
106
118
  self.save_metadata(@pupu, url)
107
- FileUtils.rm_r(".git") if Pupu.strategy.eql?(:copy)
119
+ FileUtils.rm_r(".git") if ::Pupu.strategy.eql?(:copy)
108
120
  rescue Exception => exception
109
121
  FileUtils.rm_r(repo) if File.directory?(repo)
110
122
  raise exception
@@ -112,8 +124,8 @@ module Pupu
112
124
 
113
125
  def chdir(pupu = nil, &block)
114
126
  FileUtils.mkdir_p(Pupu.root_path) unless File.directory?(Pupu.root_path)
115
- Dir.chdir(Pupu.root.to_s) do
116
- pupu ? block.call(pupu.root) : block.call(Pupu.root)
127
+ Dir.chdir(Pupu.root_path.to_s) do
128
+ pupu ? block.call(pupu.root) : block.call(Pupu.root_path)
117
129
  end
118
130
  end
119
131
  end
@@ -1,13 +1,19 @@
1
+ # encoding: utf-8
2
+
1
3
  require "pupu/parser"
2
4
 
3
5
  module Pupu
4
6
  module Helpers
7
+ def pupu_page
8
+ @page ||= Page.new
9
+ end
10
+
5
11
  # Use it in your layout
6
- # Example: pupu :autocompleter, :type => "local"
12
+ # Example: pupu :autocompleter, type: "local"
7
13
  def pupu(name, params = Hash.new)
8
14
  comment = if params.empty? then "<!-- Pupu #{name} without params -->"
9
15
  else "<!-- Pupu #{name} with params #{params.inspect} -->" end
10
- [comment, Parser.new(name, params).parse!, "", ""].join("\n")
16
+ [comment, pupu_page.parse(name, params).parse!, "", ""].join("\n")
11
17
  end
12
18
  end
13
19
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Pupu
2
4
  class Metadata
3
5
  class << self
@@ -1,19 +1,34 @@
1
+ # encoding: utf-8
2
+
1
3
  require "pupu/dsl"
2
4
  require "pupu/pupu"
3
5
 
4
6
  module Pupu
7
+ class Page
8
+ attr_reader :files
9
+ def initialize
10
+ @files = Array.new
11
+ end
12
+
13
+ def parse(name, options)
14
+ Parser.new(name, options, self)
15
+ end
16
+ end
17
+
5
18
  class Parser
6
- def initialize(plugin_name, plugin_params)
19
+ def initialize(plugin_name, plugin_params, page = Page.new)
7
20
  @plugin = Pupu[plugin_name, plugin_params]
8
21
  @output = Array.new
9
- @dsl = DSL.new(@plugin)
22
+ puts "Parser: #{page.inspect}"
23
+ @page = page
24
+ @dsl = DSL.new(@plugin, page)
10
25
  @@loaded ||= Hash.new
11
26
  @@loaded[@plugin.name] = Array.new
12
27
  end
13
28
 
14
29
  def loaded?
15
30
  # The reason why just array with plugin names isn't enough is that every time it can be called
16
- # with different parameters. For example pupu :mootools and then pupu :mootools, :more => true
31
+ # with different parameters. For example pupu :mootools and then pupu :mootools, more: true
17
32
  @@loaded[@plugin.name] && @dsl.files.all? do |file|
18
33
  @@loaded[@plugin.name].include?(file)
19
34
  end
@@ -30,7 +45,7 @@ module Pupu
30
45
 
31
46
  def add_dependencies
32
47
  @dsl.get_dependencies.each do |dependency|
33
- parser = Parser.new(dependency.name, dependency.params)
48
+ parser = Parser.new(dependency.name, dependency.params, @page)
34
49
  @output.push(parser.parse!) unless parser.loaded?
35
50
  end
36
51
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "yaml"
2
4
  require "ostruct"
3
5
  require "fileutils"
@@ -7,36 +9,63 @@ require "pupu/metadata"
7
9
 
8
10
  module Pupu
9
11
  # this must be set in adapters
10
- class << self
11
- attr_accessor :root
12
+ def self.root
13
+ @@root ||= Dir.pwd
14
+ end
12
15
 
13
- # @example Pupu.media_prefix("media").url
14
- # => "/media/pupu/autocompleter/javascripts/autocompleter.js"
15
- def media_prefix=(prefix)
16
- MediaPath.rewrite { |path| File.join(prefix, path) }
17
- end
16
+ def self.root=(path)
17
+ @@root = path
18
+ end
18
19
 
19
- # TODO: media_root or media_root?
20
- def media_root=(path)
21
- MediaPath.media_root = path
22
- @media_root = path
23
- end
24
- attr_reader :media_root
20
+ def self.framework
21
+ @@framework
22
+ end
25
23
 
26
- # @example Pupu.rewrite { |path| "http://media.domain.org/#{path}" }.url
27
- # # => "http://media.domain.org/pupu/autocompleter/javascripts/autocompleter.js"
28
- def rewrite(&block)
29
- MediaPath.rewrite(&block)
30
- end
24
+ def self.framework=(framework)
25
+ @@framework = framework
26
+ end
27
+
28
+ def self.environment?(environment)
29
+ self.environment.eql?(environment)
30
+ end
31
+
32
+ # @example Pupu.media_prefix("media").url
33
+ # => "/media/pupu/autocompleter/javascripts/autocompleter.js"
34
+ def self.media_prefix=(prefix)
35
+ MediaPath.rewrite { |path| File.join(prefix, path) }
36
+ end
37
+
38
+ def self.media_root
39
+ @@media_root ||= Dir.pwd
40
+ end
41
+
42
+ def self.media_root=(path)
43
+ MediaPath.media_root = path
44
+ @@media_root = path
45
+ end
46
+
47
+ # @example Pupu.rewrite { |path| "http://media.domain.org/#{path}" }.url
48
+ # # => "http://media.domain.org/pupu/autocompleter/javascripts/autocompleter.js"
49
+ def rewrite(&block)
50
+ MediaPath.rewrite(&block)
51
+ end
52
+
53
+ # strategies: submodules, copy
54
+ def self.strategy
55
+ @@strategy ||= :copy
56
+ end
57
+
58
+ def self.strategy=(strategy)
59
+ @@strategy = strategy
31
60
  end
32
61
 
33
62
  class Pupu
34
63
  class << self
35
64
  # TODO: return Pupu object, not string
36
65
  def all
37
- Dir["#{self.root}/*"].select do |item|
38
- File.directory?(item)
39
- end.map { |entry| File.basename(entry).to_s }
66
+ files = Dir["#{self.root_path}/*"]
67
+ dirs = files.select(&File.method(:directory?))
68
+ dirs.map(&File.method(:basename))
40
69
  end
41
70
 
42
71
  # same as root, but doesn't raise any exception
@@ -44,9 +73,6 @@ module Pupu
44
73
  File.join(::Pupu.media_root, "pupu")
45
74
  end
46
75
 
47
- # strategies: submodules, copy
48
- cattr_accessor :strategy
49
-
50
76
  def root
51
77
  # TODO: it should be configurable
52
78
  # root = ::Pupu.root.sub(%r[#{Regexp::quote(::Pupu.root)}], '').chomp("/")
@@ -58,8 +84,8 @@ module Pupu
58
84
  # # exception
59
85
  # end
60
86
  raise "Pupu.media_root has to be initialized" if ::Pupu.media_root.nil?
61
- raise Errno::ENOENT, "#{::Pupu.media_root}/pupu doesn't exist, you have to create it first!" unless File.directory?File.join(::Pupu.media_root, "pupu")
62
- @root ||= MediaPath.new(File.join(::Pupu.media_root, "pupu"))
87
+ raise Errno::ENOENT, "#{self.root_path} doesn't exist, you have to create it first!" unless File.directory?(self.root_path)
88
+ @root ||= MediaPath.new(self.root_path)
63
89
  end
64
90
 
65
91
  # TODO: reflect changes on root method
@@ -74,7 +100,7 @@ module Pupu
74
100
  if self.all.include?(plugin)
75
101
  self.new(plugin, params)
76
102
  else
77
- raise PluginNotFoundError
103
+ raise PluginNotFoundError.new(plugin)
78
104
  end
79
105
  end
80
106
  end