GithubHelp home page GithubHelp logo

_template_'s Introduction

template

Dotclear 2 template plugin

Script to migrate old code to new one (using src and namespaces)

#!/bin/sh

# Check 1st parameter (module name = directory)
if [ -z "$1" ]; then
  echo "You must give the module name = module directory"
  exit 1
fi

# Check module existance
if [ ! -d "$1" ]; then
  echo "The module $1 does not exists"
  exit 1
fi

MODULE="$1"

# Check module src subfolder
if [ ! -d "$MODULE/src" ]; then
  mkdir "$MODULE/src"
fi

MODEL="_template_"
update_ns()
{
  perl -i -pe"s/_template_/$MODULE/g" "$1"
}
make_my()
{
  if [ ! -f "$MODULE/src/My.php" ]; then
    cp "$MODEL/src/My.php" "$MODULE/src/My.php"
    update_ns "$MODULE/src/My.php"
  fi
}
make_uninstall()
{
  if [ ! -f "$MODULE/src/Uninstall.php" ]; then
    cp "$MODEL/src/Uninstall.php" "$MODULE/src/Uninstall.php"
    update_ns "$MODULE/src/Uninstall.php"
  fi
}
make_src()
{
  if [ -f "$MODULE/$1.php" ]; then
    if [ ! -f "$MODULE/src/$2.php" ]; then
      cp "$MODEL/src/$2.php" "$MODULE/src/$2.php"
      update_ns "$MODULE/src/$2.php"
      # Add a separator between new and old code
      {
        echo ""
        echo "// --- old code below ---"
        echo ""
      } >> "$MODULE/src/$2.php"
      # Add old code at the end
      tail +2 "$MODULE/$1.php" >> "$MODULE/src/$2.php"
    fi
  fi
}

# Add a src/My.php
make_my

# Move existing code to src
make_src _install Install
make_src _prepend Prepend
make_src _admin Backend
make_src _public Frontend
make_src _config Config
make_src index Manage
make_src _widgets Widgets

# Add a src/Uninstall.php
make_uninstall

The _template_ plugin and others should be in a main folder where the above script will be copy in.

Do chmod +x do_src.sh to allow execution

Do ./do_src.sh module_folder_name to run the script for the corresponding module.

Example:

AllPlugins (main folder)
|- _template_ (this repo)
|- myPlugin (a module to update)
|- myOtherPlugin (another module to update)

Do:

  • cd AllPlugins
  • ./do_src.sh myPlugin
  • ./do_src.sh myOtherPlugin

See https://open-time.net/2023/05/10/Modele-de-plugin for explanations (in French)

_template_'s People

Contributors

franck-paul avatar

Stargazers

jemattarde avatar

Watchers

 avatar

Forkers

philippe-dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.