Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature register pages #758

Closed
wants to merge 22 commits into from

Conversation

pcreux
Copy link
Contributor

@pcreux pcreux commented Nov 17, 2011

Hey @gregbell,

This branch is ready for review. Could you approve the refactorings I made?

I might add more scenarios to the feature registering_pages.

Cheers!

pcreux added 10 commits November 7, 2011 17:15
It goes like:

ActiveAdmin.page "My Page" do

  content do
    h2 "Hey, this is a custom page"
    para "Awesome!"
  end

end
Note: The documentation says that when registering a resource you can
set its name doing:

```
ActiveAdmin.register Post, :as => "Article"
```

The code however was made so that the :as resource would get a
plural. For instance:

```
ActiveAdmin.register Post, :as => "Articles"
```

I fixed this. It might be worth mentioning in the release notes.
@@ -5,23 +5,15 @@ require 'active_admin/resource_controller/callbacks'
require 'active_admin/resource_controller/collection'
require 'active_admin/resource_controller/filters'
require 'active_admin/resource_controller/form'
require 'active_admin/resource_controller/menu'
require 'active_admin/resource_controller/page_configurations'
require 'active_admin/resource_controller/scoping'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it might be worth writing some documentation on what a ResourceController is for vs. a PageController

@pcreux
Copy link
Contributor Author

pcreux commented Nov 18, 2011

@mattvague Thanks for reviewing this! :)

@@ -117,6 +117,10 @@ module ActiveAdmin
controller.set_page_config :show, options, &block
end

def content(options = {}, &block)
controller.set_page_config :index, options, &block
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of parsing the config through DSL class. There are only two methods that are relavent to a Page, #content and #menu. I wonder if instead of using the DSL, we could just assume that the block is the content and the hash options can include the menu options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have PageDSL and ContentDSL. They both inherit from DSL.

I want customisation common to both DSL (such as menu or controller) similar.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 23, 2011

Tested against a "real" rails app revealed a few regressions that I fixed. Also renamed #page method to #register_page and splitted DSL into ResourceDSL and PageDSL.

This feature is ready to be merged in.

An other thing we could do before releasing 0.4.0 is grouping classes by types in directories: controller, dsl, config.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 25, 2011

"This pull request cannot be automatically merged." Feck!

@simonoff
Copy link
Contributor

This feature must be merged!

@meskallito
Copy link

Hi
I've test your branch a bit and found issue with internalization.
Names of resources become non-latins if there are non-latin translations in active record locales.
result: namespace.rb:187:in `eval': (eval):1

@meskallito
Copy link

line number is false actually. Error appears in "register_resource_controller" function

@gregbell
Copy link
Contributor

I'll get this merged over the weekend. It's next on my list to merge :)

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

@meskallito I didn't get what the issue is. What do you mean by non Latin translation?

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

@gregbell I can fix the merge conflict if you want!

@meskallito
Copy link

Functions in module "Naming" (class Resource < Config), that were rewritten by you in commit [f5c662f], provide resource names for controller_name in class Config. The problem occurs if I have models names translations in locales (for example in Chinese), because in that case "register_page_controller" tries to create controllers with non-latin names. is it clear?
Anyway, thank you for this functionality. It really helped me.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

Ok, that makes a lot of sense!

So the user facing names (resource.name and resource.plural_name) should
use i18n while the "system" ones (camelcased and underscored) should use...
the resource one?

For now you can't register pages with non-latin names then.

I will try to fix this before 11am GMT+1 (
http://thatz.at/Nov-27-2011-11-00-GMT+1-DST) so that this can get merged
into master before we release 0.4.0.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

@meskallito said:

Functions in module "Naming" (class Resource < Config), that were rewritten by you in commit [f5c662f], provide resource names for controller_name in class Config. The problem occurs if I have models names translations in locales (for example in Chinese), because in that case "register_page_controller" tries to create controllers with non-latin names. is it clear?
Anyway, thank you for this functionality. It really helped me.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

Ok, that makes a lot of sense!

So the user facing names (resource.name and resource.plural_name) should use i18n while the "system" ones (camelcased and underscored) should use... the resource one?

For now you can't register pages with non-latin names then.

I will try to fix this before 11am GMT+1 (http://thatz.at/Nov-27-2011-11-00-GMT+1-DST) so that this can get merged into master before we release 0.4.0.

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

@gregbell I merged this branch into the current master and resolved 4 straight forward merge conflict.

It's available here: https://github.com/pcreux/active_admin/tree/merge-feature-register-pages

The feature registering_page does not pass though: http://travis-ci.org/#!/pcreux/active_admin/builds/344890

undefined local variable or method `active_admin_namespace' for #<ActiveAdmin::Views::HeaderRenderer:0xb8c2ee4> (ActionView::Template::Error)
493./lib/active_admin/arbre/builder.rb:47:in `method_missing'
494./lib/active_admin/renderer.rb:26:in `method_missing'
495./lib/active_admin/views/header_renderer.rb:16:in `title'

I let you taking care of this today. I won't have time to work on that this week-end.

FYI:
I also ran into this issue when running the specs on my machine (Ubuntu + ree 1.8.7):

Stylesheets when Rails 3.0.x should not have any syntax errors
     Failure/Error: css.should_not include("Syntax error:")
       expected "/*\nSyntax error: File to import not found or unreadable: bourbon.\n "
  [...]

@meskallito
Copy link

Yes you are right. In addition, this functions affects the process of creating a common active_admin resources. Even if I dont init any page I'll get problems in register_resource_controller' cause it uses the same config.controller_name and in router.rb (it uses underscored_resource_name). I can prepapre pull request into your branch if you want

@pcreux
Copy link
Contributor Author

pcreux commented Nov 26, 2011

@meskallito Sure, please do!

@meskallito
Copy link

@pcreux ok, I'll do in an hour or two

@pcreux
Copy link
Contributor Author

pcreux commented Nov 27, 2011

I just had to clean up my test env to get the spec to pass.

And I won't fix the non-latin support this week-end.

@gregbell
Copy link
Contributor

I rebased the branch off master and then merged it in. There are definitely some things I would like to add before releasing this with 0.4.0 such as documentation, sidebar items, action items and the issue that @meskallito is having.

Nice work @pcreux! This is an awesome feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants