Project page: http://drupal.org/sandbox/DWB/1078406

I would like to contribute a lightweight module I named 'DropIn'. It does only one thing: detect the presence of CSS files on the server based on the visitor's URL, and if present, add it to the <head> of the page. I've used this kind of functionality with the Zend framework and often found it very convenient.

For example, when a visitor requests www.example.com/news/articles/issue-1, the module will look for the next css files in the theme directory:
- news.css
- news_articles.css
- news_articles_issue-1.css
In case any of them are found, they're added to the page's css stack to do their work on (in this example) a section of pages, a sub-section or only 1 page.

The module is meant to be used by website developers / administrators.

A lot of text for a very small module, I hope it's all clear.
Kind regards

CommentFileSizeAuthor
#24 dropin_review.diff4.09 KBishanmahajan
#1 allcss.zip2.02 KBDWB Internet

Comments

DWB Internet’s picture

Component: Miscellaneous » miscellaneous
StatusFileSize
new2.02 KB

Here's my zipped module.

DWB Internet’s picture

Status: Postponed (maintainer needs more info) » Needs review
arianek’s picture

Status: Needs review » Postponed

Hi. Please read all the following and the links provided as this is very important information about your CVS Application:

Drupal.org has moved from CVS to Git! This is a very significant change for the Drupal community and for your application. Please read the following documentation on how this affects and benefits you and the application process:
Migrating from CVS Applications to (Git) Full Project Applications

  • The status of this application will be put to "postponed" and by following the instructions in the above link, you will be able to reopen it.
  • Or if your application has been "needs work" for more than 5 weeks, your application will be marked as "closed (won't fix)". You can still reopen it, by reading the instructions above.
DWB Internet’s picture

Status: Postponed » Needs review

Changed status according to instructions.

avpaderno’s picture

Status: Needs review » Postponed
DWB Internet’s picture

Project: Drupal.org CVS applications » Drupal.org security advisory coverage applications
Status: Postponed » Needs review

Link to the experimental project page: http://drupal.org/sandbox/DWB/1078406

(Acciddently I submitted this project as a new Project application as well, only later finding out I should update the submission here. See: http://drupal.org/node/1078438)

Thank you.

DWB Internet’s picture

As I added support for javascript files too, the project name didn't seem appropriate anymore so I changed it into 'DropIn'.
(I haven't yet adapted the code to the new name).

DWB Internet’s picture

Title: DWB [dwb] » DropIn

Changed the name of this thread to better accommodate the module.

DWB Internet’s picture

Component: miscellaneous » new project application
sreynen’s picture

Status: Needs review » Needs work

Hi DWB,

I see a few issues with your code. First, you should install http://drupal.org/project/coder and fix any issues it reports. Most of what I see are whitespace issues, but there might be more. In addition to what coder will tell you, some other feedback:

  • You don't need allcss_install() at all; Drupal core already sets a message when modules are enabled.
  • The nbproject directory should be removed from the git repository, or at least any stable release. That's cruft for end users.
  • You should remove the // $id$ everywhere. Those were important for CVS, but unneeded on Git.
  • _allcss_settings_form should not start with an underscore. The underscore indicates a private method, and anything using form API can't really be private.
  • hook_html_head_alter() seems like the wrong place to be adding the CSS and JS, since you're not altering the $head_elements at all. I'd probably do that in hook_init(), though someone else might know of a better place.
DWB Internet’s picture

Component: new project application » module
Status: Needs work » Needs review

Thanks for your review sreynen!

I made the suggested changes and reformatted some of the code according to the coding standards (I thought I had the formatting right in the first place but there were a few spaces and tabs in places they didn't belong).

nbproject directory, $id$'s, ill-placed underscores and hook_install() are removed.

DWB Internet’s picture

Issue summary: View changes

removed some needless text

sreynen’s picture

Status: Needs review » Needs work

Hi DWB,

Sorry this has been waiting so long. We have a huge backlog on reviews and not enough volunteer hours to look at them quickly. I just looked at this again and see some issues:

  • You changed the name of allcss_settings_form(), but allcss_menu() still references that function by the old name.
  • allcss_init() has a parameter, which isn't used anywhere and should be removed. Also because hook_init() takes no parameters.
  • Minor issue: the indentation is inconsistant. For example, the returns at the end of both allcss_settings_form() and allcss_help() are indented much further than the rest of those functions.
  • allcss_uninstall() is deleting allcss_subdir, which is never set, but not deleting allcss_css_subdir nor allcss_js_subdir, which are set.
DWB Internet’s picture

Hi sreynen,

Thanks for your review. It's suprising to see how many small deficiencies can be found when the code is reviewed through someone else's eyes.. I applied your proposed changes and retested the module to make sure everything still works as planned after the changes I made. Looking forward to your opinion.

Regards

DWB Internet’s picture

Status: Needs work » Needs review
jthorson’s picture

Status: Needs review » Needs work

A few more (trivial) points:

  1. I'd suggest adding add a README.txt file to the project repository ... See http://drupal.org/node/447604
  2. The project page description could use a bit more elaboration as well, IMO. It left me scratching my head as to what this did. Then I read your application text (from above), which does a much better job of explaining the module.
  3. Missing translation call on the second part of the output:
    $output .= '<strong>' . t('news_articles.css') . '</strong>' . ' - styles all pages under news/articles/<br />';
    $output .= '<strong>' . t('news_articles_issue-1.css') . '</strong>' . ' - only styles the page issue-1</p>';

Interesting concept, and looks well executed ... as a feature suggestion, it would be nice to have an admin setting where you define specific paths where this check is invoked (similar to the 'show this block on:' path listing on block config pages), instead of having the hook_init script run on every single page.

jthorson’s picture

Issue summary: View changes

Small text modification

DWB Internet’s picture

Issue summary: View changes

minor change

DWB Internet’s picture

Status: Needs review » Needs work

Thanks for your suggestions, jthorson. I didn't know a readme file was mandatory for modules, I found out by reading http://drupal.org/node/447604. So I added it to DropIn. I also implemented the missing translations.

Your feature suggestion (admin setting to define paths) is certainly worth considering. It could have a button to detect the files and cache them so you wouldn't have to add them manually.

Regards

DWB Internet’s picture

Status: Needs work » Needs review
klausi’s picture

DWB Internet’s picture

Status: Needs work » Needs review

Hi klausi, thanks for your extensive and well-documented review! My reworked code now can be found in the major version branch (7.x-1.x).

Apart from he issues you listed, I ran the module through coder which I hope has solved all the formatting issues.

Regards

glekli’s picture

Status: Needs review » Needs work

After reviewing your module, I have to say I did not find many things that could be an issue. Here is one, though:

In line 20, why do you use DIRECTORY_SEPARATOR to split a Drupal path? On Win servers it is set to backslash, although the Drupal path is always separated with forward slashes. Also, the PHP function split() is deprecated; you could use explode() instead.

DWB Internet’s picture

Status: Needs work » Needs review

Hi Gergely, thanks for reviewing DropIn!

You're right about the DIRECTORY_SEPARATOR. In general I suppose it's good practice to use DIRECTORY_SEPARATOR for splitting/exploding paths that are given by the OS, which of course is not the case here.

In my memory explode() was the deprecated one but I see you're right.

I followed both your suggesions and changed the code.

Regards.

klausi’s picture

Status: Needs review » Needs work

Review of the 7.x-1.x branch:

  • Run coder to check your style, some issues were found (please check the Drupal coding standards):
    Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards
    
    sites/all/modules/pareview_temp/test_candidate/allcss.module:
     +58: [normal] Menu item titles and descriptions should NOT be enclosed within t().
     +61: [minor] There should be no trailing spaces
     +85: [normal] Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE
     +93: [normal] Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE
     +109: [normal] String concatenation should be formatted with a space separating the operators (dot .) and the surrounding terms
     +110: [normal] String concatenation should be formatted with a space separating the operators (dot .) and the surrounding terms
    
    Status Messages:
     Coder found 1 projects, 2 files, 5 normal warnings, 1 minor warnings, 0 warnings were flagged to be ignored
    

This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.

DWB Internet’s picture

Status: Needs work » Needs review

Thanks for your patience, Klausi (and other reviewers)! In #19 I ran my code through the online coder instead of the module, which probably explains the issues I missed. I Installed and used the module this time, giving me the same results as yours.

I solved the issues and uploaded the reworked code.

Regards

ishanmahajan’s picture

Status: Needs review » Needs work
StatusFileSize
new4.09 KB

Hi DWetc,

Review of 7.x-1.x branch:
The issues pointed in #22 are fixed. The module passed coder.

Some suggestions:

  • You mentioned that you changed the project name to DropIn. The name of the module file should be dropin.module and not allcss.module. The install file, info file names and the function names also need to be changed.
  • line 24: removed extra space after "head"
  • line 30 and line 40: file_exists can check for relative paths. There is no need for dirname function.
  • line 34 and line 44: defined a constant 'JS_DROPIN'. It is better to use a constant here.
  • line 50: removed the extra line between two functions.
  • line 61: removed extra space from the end of the line.
  • line 78,87,95:removed '#required => FALSE' as false is the default value.
  • line 112: replaced website.com with the standard example.com

Attaching the patch.

DWB Internet’s picture

Thanks for your review ishanmahajan, and the patch included.

You're probably right in that using 'dropin' in the code and file names adds to the clarity of the module and the code. So I fixed that.

Line 34 and line 44: defined a constant 'JS_DROPIN'. It is better to use a constant here.

I've applied your patch except for the above part. I don't see why using a constant here would be better. Could you explain why you think so?

Otherwise all issues fixed.

DWB Internet’s picture

Status: Needs work » Needs review

(Forgot to change status)

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

ishanmahajan’s picture

Hi DWetc,

Using a constant here is not a big deal. It just makes the program easier to read and modify IMO. The module looks really good to me.

greggles’s picture

Status: Reviewed & tested by the community » Fixed

Please take a moment to make your project page follow tips for a great project page.

Thanks for your contribution, DWetc! Welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in minde: Commit messages - providing history and credit and Release naming conventions.

DWB Internet’s picture

Thanks Greggles and everyone who took the time to review my code and help me make this into a Drupal worthy project!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added link to he project page