zen 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGELOG.md +12 -2
  2. data/MANIFEST +17 -10
  3. data/ROADMAP.md +8 -4
  4. data/bin/zen +2 -3
  5. data/lib/zen.rb +20 -14
  6. data/lib/zen/bin/{zen_binary.rb → base.rb} +0 -0
  7. data/lib/zen/controller/main_controller.rb +7 -4
  8. data/lib/zen/{base/database.rb → database.rb} +3 -2
  9. data/lib/zen/error/language_error.rb +10 -0
  10. data/lib/zen/error/package_error.rb +10 -0
  11. data/lib/zen/error/plugin_error.rb +10 -0
  12. data/lib/zen/error/theme_error.rb +10 -0
  13. data/lib/zen/helper/acl.rb +11 -4
  14. data/lib/zen/{base/language.rb → language.rb} +11 -3
  15. data/lib/zen/layout/admin.xhtml +21 -12
  16. data/lib/zen/layout/login.xhtml +17 -11
  17. data/lib/zen/liquid/general.rb +1 -27
  18. data/lib/zen/{base/logger.rb → logger.rb} +0 -0
  19. data/lib/zen/{base/package.rb → package.rb} +65 -55
  20. data/lib/zen/package/all.rb +5 -0
  21. data/lib/zen/package/categories/lib/categories.rb +7 -8
  22. data/lib/zen/package/comments/lib/comments.rb +7 -8
  23. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +1 -1
  24. data/lib/zen/package/comments/lib/comments/liquid/comments.rb +3 -1
  25. data/lib/zen/package/custom_fields/lib/custom_fields.rb +7 -8
  26. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +14 -0
  27. data/lib/zen/package/custom_fields/migrations/1295255665_create_schema.rb +1 -1
  28. data/lib/zen/package/menus/lib/menus.rb +5 -6
  29. data/lib/zen/package/sections/lib/sections.rb +4 -5
  30. data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +2 -2
  31. data/lib/zen/package/sections/lib/sections/liquid/section_entries.rb +9 -2
  32. data/lib/zen/package/settings/lib/settings.rb +7 -8
  33. data/lib/zen/package/users/lib/users.rb +7 -8
  34. data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +5 -5
  35. data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +4 -4
  36. data/lib/zen/plugin.rb +172 -0
  37. data/lib/zen/plugin/markup.rb +30 -0
  38. data/lib/zen/public/admin/css/layout.css +17 -0
  39. data/lib/zen/strict_struct.rb +36 -0
  40. data/lib/zen/task/db.rb +14 -4
  41. data/lib/zen/task/package.rb +13 -8
  42. data/lib/zen/task/theme.rb +88 -0
  43. data/lib/zen/theme.rb +129 -0
  44. data/lib/zen/{base/version.rb → version.rb} +1 -1
  45. data/proto/app/config/config.rb +19 -6
  46. data/proto/app/config/database.rb +58 -2
  47. data/proto/app/config/middlewares.rb +69 -4
  48. data/proto/app/config/requires.rb +9 -2
  49. data/proto/app/{logs → log}/.gitkeep +0 -0
  50. data/proto/package/lib/package.rb +3 -13
  51. data/proto/package/lib/package/controller/controllers.rb +5 -9
  52. data/proto/package/lib/package/language/en/languages.yml +4 -0
  53. metadata +66 -26
  54. data/proto/package/LICENSE +0 -0
  55. data/proto/package/README.textile +0 -0
  56. data/proto/package/lib/package/language/en/languages.rb +0 -3
@@ -0,0 +1,88 @@
1
+ Sequel.extension(:migration)
2
+
3
+ module Zen
4
+ module Task
5
+ ##
6
+ # The Theme task is used to install, delete and manage Zen themes.
7
+ #
8
+ # @author Yorick Peterse
9
+ # @since 0.2.4
10
+ #
11
+ class Theme < Thor
12
+ namespace :theme
13
+
14
+ desc('list', 'Lists all installed themes')
15
+
16
+ ##
17
+ # Lists all installed themes
18
+ #
19
+ # @author Yorick Peterse
20
+ # @since 0.2.4
21
+ #
22
+ def list
23
+ table = []
24
+ table.push(['Name', 'Author', 'Identifier', 'Templates'])
25
+ table.push(['------', '------', '------', '------'])
26
+
27
+ Zen::Theme.themes.each do |ident, theme|
28
+ table.push([theme.name, theme.author, theme.identifier, theme.template_dir])
29
+ end
30
+
31
+ print_table(table)
32
+ end
33
+
34
+ desc('migrate', 'Migrates a theme to the given version')
35
+
36
+ method_option(:version , :type => :numeric, :default => nil)
37
+ method_option(:identifier, :type => :string , :default => nil, :required => true)
38
+
39
+ ##
40
+ # Migrates a theme to the given version.
41
+ #
42
+ # @author Yorick Peterse
43
+ # @since 0.2.4
44
+ #
45
+ def migrate
46
+ version = options[:version]
47
+ ident = options[:identifier]
48
+
49
+ if Zen::Theme.themes.nil? or Zen::Theme.themes.empty?
50
+ abort "No themes have been loaded. Be sure to add them to config/requires.rb."
51
+ end
52
+
53
+ if version.nil?
54
+ puts "No version specified with --version, choosing the most recent version..."
55
+ end
56
+
57
+ install_theme = Zen::Theme[ident]
58
+
59
+ if ident.nil? or ident.empty?
60
+ abort "You specified an invalid identifier."
61
+ end
62
+
63
+ # Get the directory from the migration_dir getter, generate it if it isn't there.
64
+ if install_theme.respond_to?(:migration_dir) and !install_theme.migration_dir.nil?
65
+ dir = install_theme.migration_dir
66
+ else
67
+ abort "The specified theme has no migrations directory"
68
+ end
69
+
70
+ table = install_theme.identifier.gsub('.', '_').to_sym
71
+
72
+ puts "Migrating theme..."
73
+ if File.directory?(dir)
74
+ Zen::Database.handle.transaction do
75
+ Sequel::Migrator.run(Zen::Database.handle, dir, :table => table, :target => version)
76
+
77
+ if version == 0
78
+ # Remove the migrations table
79
+ Zen::Database.handle.drop_table table
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+ end
88
+
@@ -0,0 +1,129 @@
1
+ require __DIR__('error/theme_error')
2
+ require 'pathname'
3
+
4
+ #:nodoc:
5
+ module Zen
6
+ ##
7
+ # Themes in many ways are similar to plugins and packages but with a few differences.
8
+ # Unlike packages themes aren't able to update the entire Ramaze root, this prevents
9
+ # them from loading controllers and other classes unless the developer updates these
10
+ # paths manually. However, themes can set the following paths:
11
+ #
12
+ # * template_dir: the directory where all Liquid templates are located, always required.
13
+ # * partial_dir: the directory where all Liquid partials are located.
14
+ # * public_dir: the public directory containing assets such as CSS and Javascript files.
15
+ # * migration_dir: themes can use migrations to automatically add the required fields to
16
+ # the database, this setting should point to the directory where all migrations are
17
+ # located.
18
+ #
19
+ # ## Adding Themes
20
+ #
21
+ # Just like plugins and packages a theme can be added by calling Zen::Theme#add and
22
+ # passing a block to it. Once a theme has been loaded it will *not* be used until the
23
+ # user sets it as the active theme in the settings module.
24
+ #
25
+ # Example:
26
+ #
27
+ # Zen::Theme.add do |theme|
28
+ # theme.author = 'Yorick Peterse'
29
+ # theme.name = 'Default'
30
+ # theme.identifier = 'com.yorickpeterse.theme.default'
31
+ # end
32
+ #
33
+ # The "identifier" key is very important and just like packages and plugins it should
34
+ # always stay the same once it has been set.
35
+ #
36
+ # ## Identifiers
37
+ #
38
+ # Theme identifiers should be in the following format:
39
+ #
40
+ # com.VENDOR.theme.NAME
41
+ #
42
+ # For example:
43
+ #
44
+ # com.yorickpeterse.theme.fancy_blog
45
+ #
46
+ # @author Yorick Peterse
47
+ # @since 0.2.4
48
+ # @attr_reader [Array] themes Array of all installed themes.
49
+ #
50
+ module Theme
51
+ class << self
52
+ attr_reader :themes
53
+ end
54
+
55
+ ##
56
+ # Adds a new theme to Zen. Note that the theme won't be used unless it has been set
57
+ # as the active theme in the settings package.
58
+ #
59
+ # @author Yorick Peterse
60
+ # @since 0.2.4
61
+ # @yield [theme] Struct object containing all getter/setters for each theme.
62
+ #
63
+ def self.add
64
+ @themes ||= {}
65
+
66
+ required = [:name, :author, :about, :identifier, :template_dir]
67
+ theme = Zen::StrictStruct.new(
68
+ :name, :author, :about, :url, :identifier, :template_dir, :partial_dir,
69
+ :public_dir, :migration_dir
70
+ ).new
71
+
72
+ yield theme
73
+
74
+ # Check if all required items have been set
75
+ theme.validate(required) do |k|
76
+ raise(Zen::ThemeError, "The following theme key is missing: #{k}")
77
+ end
78
+
79
+ # Validate all paths set
80
+ [:template_dir, :partial_dir, :public_dir, :migration_dir].each do |k|
81
+ # Only validate the path if it has been set
82
+ if theme.respond_to?(k) and !theme.send(k).nil? and !theme.send(k).empty?
83
+ if !File.exist?(theme.send(k))
84
+ raise(Zen::ThemeError, "The path #{k} doesn't exist.")
85
+ end
86
+ end
87
+ end
88
+
89
+ # Do we have a public directory?
90
+ if theme.respond_to?(:public_dir) and !theme.public_dir.nil?
91
+ if !Ramaze.options.publics.include?(theme.public_dir)
92
+ # Generate a relative path from ROOT to the theme
93
+ to = Pathname.new(theme.public_dir)
94
+ from = Pathname.new(Zen.options.root)
95
+ dir = to.relative_path_from(from.realpath).to_s
96
+
97
+ Ramaze.options.publics.push(dir)
98
+ end
99
+ end
100
+
101
+ if !@themes[theme.identifier].nil?
102
+ raise(Zen::ThemeError, "The theme #{theme.name} already exists.")
103
+ end
104
+
105
+ @themes[theme.identifier] = theme
106
+ end
107
+
108
+ ##
109
+ # Retrieves a single theme for hte given identifier.
110
+ #
111
+ # @author Yorick Peterse
112
+ # @since 0.2.4
113
+ # @param [String] ident The identifier of the theme.
114
+ # @return [Struct] Instance of the theme.
115
+ #
116
+ def self.[](ident)
117
+ if @themes.nil?
118
+ raise(Zen::ThemeError, "No themes have been added.")
119
+ end
120
+
121
+ if !@themes[ident]
122
+ raise(Zen::ThemeError, "The theme #{ident} doesn't exist.")
123
+ end
124
+
125
+ return @themes[ident]
126
+ end
127
+
128
+ end
129
+ end
@@ -8,5 +8,5 @@ module Zen
8
8
  # @author Yorick Peterse
9
9
  # @since 0.1
10
10
  #
11
- Version = '0.2.3'
11
+ Version = '0.2.4'
12
12
  end
@@ -1,17 +1,30 @@
1
+ ##
1
2
  # Specify the root directory. This is required since there are multiple directories
2
3
  # to load resources from. This directory will be used for the database logger, modes, etc.
4
+ #
3
5
  Zen.options.root = __DIR__('../')
4
6
 
5
- # General configuration options
7
+ ##
8
+ # UTF-8 bitches.
9
+ #
6
10
  Zen.options.encoding = 'utf8'
7
11
 
8
- # Localization settings
12
+ ##
13
+ # Sets the language to use in the event of the database settings not being set correctly.
14
+ #
9
15
  Zen.options.language = 'en'
10
16
 
17
+ ##
11
18
  # Set the application's mode. Available modes are "dev" and "live"
12
- Ramaze.options.mode = :dev
19
+ #
20
+ Ramaze.options.mode = :dev
13
21
 
14
- # Configure sessions
15
- Ramaze.options.session.key = 'zen.sid'
22
+ ##
23
+ # The session identifier to use for cookies.
24
+ #
25
+ Ramaze.options.session.key = 'zen.sid'
16
26
 
17
- Ramaze::View.options.cache = false
27
+ ##
28
+ # View caching.
29
+ #
30
+ Ramaze::View.options.cache = false
@@ -1,18 +1,74 @@
1
- # Database configuration
1
+ ##
2
+ # Database group to use for developing the website.
3
+ #
4
+ # The following options can be set:
5
+ #
6
+ # * adapter: the SQL adapter used by Sequel to connect to the database. Examples of these
7
+ # are mysql2, postgres, sqlite, etc.
8
+ # * host: the hostname of the database server.
9
+ # * username: the name of the user used for connecting to the database
10
+ # * password: the password of the user used for connecting to the database.
11
+ # * database: the name of the database to use.
12
+ #
13
+ # IMPORTANT: it's recommended to create a database user for your Zen application and
14
+ # prevent it from being able to access other databases. Zen is new and may allow hackers
15
+ # to exploit the system. Using an isolated user would prevent hackers from destroying
16
+ # all databases.
17
+ #
2
18
  Zen::Database.mode :dev do |db|
19
+ ##
20
+ # Example: mysql2
21
+ #
3
22
  db.adapter = ''
23
+
24
+ ##
25
+ # Example: localhost
26
+ #
4
27
  db.host = ''
5
28
 
29
+ ##
30
+ # Example: zen-app
31
+ #
6
32
  db.username = ''
33
+
34
+ ##
35
+ # Example: 23x190jj38123x
36
+ #
7
37
  db.password = ''
38
+
39
+ ##
40
+ # Example: blog
41
+ #
8
42
  db.database = ''
9
43
  end
10
44
 
45
+ ##
46
+ # Database group to use for your production server.
47
+ # This group accepts the same settings as the block above.
48
+ #
11
49
  Zen::Database.mode :live do |db|
50
+ ##
51
+ # Example: mysql2
52
+ #
12
53
  db.adapter = ''
54
+
55
+ ##
56
+ # Example: localhost
57
+ #
13
58
  db.host = ''
14
59
 
60
+ ##
61
+ # Example: zen-app
62
+ #
15
63
  db.username = ''
64
+
65
+ ##
66
+ # Example: 23x190jj38123x
67
+ #
16
68
  db.password = ''
69
+
70
+ ##
71
+ # Example: blog
72
+ #
17
73
  db.database = ''
18
- end
74
+ end
@@ -1,17 +1,82 @@
1
- # Put your custom development modes in here
1
+ ##
2
+ # All Rack middlewares should go in a block like the one below. Different combinations
3
+ # can be used for different versions by setting the first argument of the middleware!
4
+ # method to a symbol containing the name of the environment (e.g. :live).
5
+ #
6
+ # For development purposes we'll be loading various middlewares to make it easier to
7
+ # detect errors, reloading the code and so on.
8
+ #
2
9
  Ramaze.middleware! :dev do |m|
10
+ ##
11
+ # Rack::Lint is used to validate all code according to the Rack specification.
12
+ # It's not recommended to use this middleware in a production environment as it will
13
+ # slow your application down a bit.
14
+ #
3
15
  m.use Rack::Lint
16
+
17
+ ##
18
+ # Rack::CommonLogger is used to log requests in an Apache like format. Zen ships with
19
+ # a small extension of Ramaze::Log::RotatingInformer that automatically creates the
20
+ # required directories for each mode and group (database, server, etc) but any Rack
21
+ # compatible logger will do.
22
+ #
4
23
  m.use Rack::CommonLogger, Zen::Logger.new("#{Zen.options.root}/log/server")
24
+
25
+ ##
26
+ # Shows an error page whenever an exception was raised. It's not recommended to use
27
+ # this middleware on a production server as it may reveal sensitive details to the
28
+ # visitor.
29
+ #
5
30
  m.use Rack::ShowExceptions
31
+
32
+ ##
33
+ # Pretty much the same as Rack::ShowExceptions.
34
+ #
6
35
  m.use Rack::ShowStatus
7
- m.use Rack::RouteExceptions
8
- m.use Rack::ConditionalGet
9
- m.use Rack::ETag, 'public'
36
+
37
+ ##
38
+ # Routes exceptions to different actions, can be useful for catching 404's and such.
39
+ #
40
+ # m.use Rack::RouteExceptions
41
+
42
+ ##
43
+ # Middleware that enables conditional GET using If-None-Match and If-Modified-Since.
44
+ # Currently Zen doesn't respond to conditional GET requests so it's fairly useless
45
+ # out of the box, it can be useful for custom extensions and such.
46
+ #
47
+ # m.use Rack::ConditionalGet
48
+
49
+ ##
50
+ # Automatically sets the ETag header on all string bodies. Etags can be useful for
51
+ # checking if a certain page has been modified or not.
52
+ #
53
+ # IMPORTANT: Prior to Rack 1.2.2 Rack::ETag required the second argument of use() to
54
+ # be set to 'public'. Newer versions no longer require this.
55
+ #
56
+ m.use Rack::ETag
57
+
58
+ ##
59
+ # Allows HEAD requests. HEAD requests are identical to GET requests but shouldn't
60
+ # return the body.
61
+ #
10
62
  m.use Rack::Head
63
+
64
+ ##
65
+ # Automatically reloads your application whenever it detects changes. Note that this
66
+ # middleware isn't always as accurate so there may be times when you have to manually
67
+ # restart your server.
68
+ #
11
69
  m.use Ramaze::Reloader
70
+
71
+ ##
72
+ # Runs Ramaze based on all mappings and such.
73
+ #
12
74
  m.run Ramaze::AppMap
13
75
  end
14
76
 
77
+ ##
78
+ # Middlewares to use for a production environment.
79
+ #
15
80
  Ramaze.middleware! :live do |m|
16
81
  m.use Rack::CommonLogger, Zen::Logger.new("#{Zen.options.root}/log/server")
17
82
  m.use Rack::RouteExceptions
@@ -1,3 +1,10 @@
1
-
2
- # Load all core extensions that ship with Zen
1
+ ##
2
+ # Load all core extensions that ship with Zen.
3
+ #
3
4
  require 'zen/package/all'
5
+
6
+ ##
7
+ # All custom gems can go in here.
8
+ #
9
+ # require 'rdiscount'
10
+ # require 'foobar'
File without changes
@@ -1,8 +1,4 @@
1
-
2
1
  Zen::Package.add do |p|
3
- # The type of extension. Can either be "theme" or "extension".
4
- p.type = ''
5
-
6
2
  # The name of the package
7
3
  p.name = ''
8
4
 
@@ -12,26 +8,20 @@ Zen::Package.add do |p|
12
8
  # A URL to a page about the package
13
9
  p.url = ''
14
10
 
15
- # The version number of the package
16
- p.version = '1.0'
17
-
18
11
  # Describe what your theme or extension does.
19
12
  p.about = ''
20
13
 
21
14
  ##
22
15
  # An identifier is a unique string for your package in the following format:
23
16
  #
24
- # * com.AUTHOR.NAME for extensions
25
- # * com.AUTHOR.themes.NAME for themes
26
- #
27
- # An example of this would be "com.zen.sections" or "com.zen.themes.zen_website".
17
+ # com.VENDOR.NAME
28
18
  #
29
- p.identifier = 'com.author.module'
19
+ p.identifier = 'com.vendor.module'
30
20
 
31
21
  ##
32
22
  # Path to the directory containing the controllers, models, etc.
33
23
  #
34
- p.directory = __DIR__('modules')
24
+ p.directory = __DIR__('package')
35
25
 
36
26
  # Note that themes can not have menu items (they'll be ignored).
37
27
  p.menu = [{